Lee*_*eem 1 html javascript jquery jquery-ui javascript-events
我有一个带有表格的index.html页面:
<body>
<table class="mytable">
<tr id="1">
<td>John</td>
<td>123</td>
</tr>
<tr id="2">
<td>Kate</td>
<td>456</td>
</tr>
</table>
<script src="my.js"></script>
</body>
Run Code Online (Sandbox Code Playgroud)
我已将my.js包含在我的页面中,我试图在my.js中以下列方式获取鼠标单击行的id:
$('.mytable tr').click(function(e){
alert('clicked.'); //even did not get alert here.
var rowId = $(this).attr('id');
alert(rowId);
});
Run Code Online (Sandbox Code Playgroud)
但我没有得到点击行的行ID(没有警报),我在哪里错了?
- -解 - -
我的坏,我有一个地方清空了桌子,这意味着没有tr.这就是为什么它不起作用.很抱歉打扰.
| 归档时间: |
|
| 查看次数: |
1159 次 |
| 最近记录: |