请看小提琴。当我单击单元格时,我可以获得值和列名。我想知道如何获取行和列索引?以下是js代码,
<script type="text/javascript">
$(document).ready(function(){
$('#example tbody').on( 'click', 'td', function () {
alert('Data:'+$(this).html().trim());
alert('Row:'+$(this).parent().find('td').html().trim());
alert('Column:'+$('#example thead tr th').eq($(this).index()).html().trim());
});
});
</script>
Run Code Online (Sandbox Code Playgroud) 有没有办法获取类名的索引(即类"className"的第三个元素是3而不使用jQ?
我不知道jQ,我现在没时间学习它,我不想在代码中包含我至少不了解的代码.
谢谢.
顺便说一下,我使用了jQ而不是拼写出来,所以如果有人有同样的问题,这些结果可以在Google中过滤掉.如果我拼写出来,并且有人在Google中使用了NOT运算符,那么这个运算符也会消失.
我有一个div中的元素集合
让我们说:
<div>
<p id="one">one</p>
<p id="two">two</p>
<p id="three">three</p>
<p id="four">four</p>
</div>
Run Code Online (Sandbox Code Playgroud)
现在我正在寻找一种简单的方法来查找索引,让我们说第三个元素如下:
document.getElementById("three").index();
Run Code Online (Sandbox Code Playgroud)
这应该返回一个值为2的整数,因为这个元素是第三个
我知道在jquery中有这样的东西,但我会喜欢普通的js