答案 0 :(得分:1)
您可以通过查看event.target
属性
$(document).ready(function() {
$('table tr').click(function(e) {
if ($(e.target).is(':button')) {
snippet.log('button clicked')
return;
}
snippet.log('row clicked');
var href = $(this).attr("data-url");
if (href) {
//console.log('redirect to:' + href);
window.location = href;
}
});
});

<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr data-url="link.html">
<td>Some Text Value
<input type="button" value="Submit" onclick="otherFunction()">
</td>
</tr>
<tr data-url="link2.html">
<td>Some Text Value
<input type="button" value="Submit" onclick="otherFunction()">
</td>
</tr>
<tr data-url="link3.html">
<td>Some Text Value
<input type="button" value="Submit" onclick="otherFunction()">
</td>
</tr>
</table>
&#13;
答案 1 :(得分:1)
您必须查看传递给target
函数的event
的{{1}}。
这是一个有效的例子:
click
&#13;
$(document).ready(function(){
$(".clickablerow").click(function(event) {
if(event.target.tagName != "INPUT"){
var href = $(this).attr("data-url");
if(href) {
//console.log('redirect to:' + href);
window.location = href;
}
}
});
});
function otherFunction() {
alert("other function");
}
&#13;