stop event propagation when the event handler function takes arguments
say you have
<tr onclick="viewJob(11)">
<td>Job Id: 11</td>
<td><input type="button" onclick="cancelJob(11)"/></td>
</tr>
When clicking the button in the TD, I want to开发者_开发问答 avoid executing viewJob() on the TR. I've seen how to do this with cancelJob(e), but how do you do this when you have function parameters?
The way you are doing things can make things inaccessible to users without javascript, and those with screen readers.
I would recommend just putting in an tag inside each element.
Otherwise, put the onclick on the element
Problem solved.
Can't you just pass the function parameters in the call after you pass in the event object?
So:
cancelJob(e, 11);
Then your js function would be:
function cancelJob(evt, jobId)
{
}
I would think this would work fine.
Though you should consider separating the js from the html but that is for a different question.
精彩评论