本文实例讲述了JQuery使用index方法获取Jquery对象数组下标的方法。分享给大家供大家参考。具体实现方法如下:
/p>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
index方法获取Jquery对象的数组下标#main{
width:600px;
border:1px solid green;
margin:auto;
padding:10px;
}
#tbl{
border-collapse:collapse;
border-top:1px solid red;
border-left:1px solid red;
margin:auto;
}
#tbl td{
width:60px;
height:60px;
border-collapse:collapse;
border-bottom:1px solid red;
border-right:1px solid red;
}
var oldColor;
$(function () {
$("#tbl tr").hover(
function () {
oldColor = $(this).css("backgroundColor");
$(this).css("backgroundColor", "yellow");
},
function () {
$(this).css("backgroundColor", oldColor);
});
$("#tbl tr").click(function () {
alert($("#tbl tr").index($(this))); //获取元素下标
});
});
1 | 1 | 1 |
2 | 2 | 2 |
3 | 3 | 3 |
4 | 4 | 4 |
5 | 5 | 5 |
6 | 6 | 6 |
希望本文所述对大家的jQuery程序设计有所帮助。