gpt4 book ai didi

javascript - 获取表行号?

转载 作者:行者123 更新时间:2023-11-27 22:37:26 25 4
gpt4 key购买 nike

我想获取点击的表格行号。表仅在 table-body 上有 id,在 table、tr 和 td 上没有 id

问题:

如何获取我点击的行号?

test.prototype.clickRowDisplay = function () {

//code

};

最佳答案

这对您有帮助:

$("table tr").on("click",function(index){
alert("You Click Number : " + ($(this).index() + 1));
})

最终代码:

<html>
<head>
<meta charset="utf-8">
</head>
<body>
<table border="1">
<tr><td>Ehsan</td><td>Taghdisi</td></tr>
<tr><td>Amin</td><td>Abbas</td></tr>
<tr><td>Saeed</td><td>Hassani</td></tr>
<tr><td>Karim</td><td>kazem</td></tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("table tr").on("click",function(index){
alert("You Click Number : " + ($(this).index() + 1));
})
})
</script>
</body>
</html>

关于javascript - 获取表行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38993403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com