【发布时间】:2016-02-02 03:43:14
【问题描述】:
我试图在 jquery 的帮助下使用 alert 函数获取表的行索引,但我无法获得任何输出。当我点击编辑按钮时,没有任何动作
<html>
<head>
<script type="text/javascript">
function check(){
$("table tr").click(function() {
alert( this.rowIndex ); // alert the index number of the clicked row.
});
}
</script>
</head>
<table>
<tr>
<td> <input type="button" name="test" value="Edit" id="amol" onclick="check();"/> </td>
</tr>
</table>
</html>
请帮帮我!
【问题讨论】:
-
因为页面
function check(el) { alert(el.rowIndex); // alert the index number of the clicked row. }中没有包含jQuery,所以onclick="check(this);"就可以了 -
$("table tr") 这会搜索 id 为 "table tr" 的元素,而不是原来的类型。
-
存在语法错误。这应该会有所帮助。 stackoverflow.com/questions/4524661/…>
标签: javascript jquery