我有一个像这样的html表:
<table id="top10ItemsTable">
<tr>
<th>Item Code</th>
<th>Description</th>
<th class="rightjustifytext">Qty</th>
</tr>
. . .
我想回复该表中的点击,因此将其添加到就绪函数中:
$("body").on("click", "#top10ItemsTable", function () {
alert('you clicked inside the Top 10 Items quadrant table');
});
...但是点击html表不会产生任何警报,除非它是微观的或不可见的。
需要什么才能把桌子狠狠地捅到桌子上?
答案 0 :(得分:2)
你可以这样做:
$("#top10ItemsTable").click(function () {
alert('you clicked inside the Top 10 Items quadrant table');
}
答案 1 :(得分:1)
试试这个:
$(document).on("click", "#top10ItemsTable", function () {
alert('you clicked inside the Top 10 Items quadrant table');
})
最终代码:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<table id="top10ItemsTable">
<tr>
<th>Item Code</th>
<th>Description</th>
<th class="rightjustifytext">Qty</th>
</tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).on("click", "#top10ItemsTable", function () {
alert('you clicked inside the Top 10 Items quadrant table');
})
</script>
</body>
</html>