我想写一个js用于获取某个对象现在有一个input 在一个table里面<table id="tblGrid2">
<input tabindex=12/>
<input tabindex=13/>
</table>
如何通过this获取<input tabindex=13/>这个对象。类似如下,不过如下这个是不行的。
$(":input[tabindex=" + tabIndex + "]", this).focus();this 是table的对象。
<input tabindex=12/>
<input tabindex=13/>
</table>
如何通过this获取<input tabindex=13/>这个对象。类似如下,不过如下这个是不行的。
$(":input[tabindex=" + tabIndex + "]", this).focus();this 是table的对象。
var tabIndex = 13;
$(":input[tabindex='" + tabIndex + "']", $("#tblGrid2")).focus();
<table id="tblGrid2">
<tr>
<td>
<input tabindex=12/>
<input tabindex=13/>
</td>
</tr>
</table>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$('table').each(function(){
alert( $(":input[tabindex=12]", this).attr('tabindex') )
})
</script>
<input tabindex=12/>
<input tabindex=13/>
</table>ff下生成的结构是这样的
<input tabindex="12/">
<input tabindex="13/">
<table id="tblGrid2"> </table>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>修改对象原型</title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
$(":input[tabindex='13']", $("#tblGrid2")).focus();
}
</script>
</head>
<body>
<table id="tblGrid2">
<input tabindex=12 />
<input tabindex=13/>
</table>
</body>
</html>
</body>
</html>
<script type="text/javascript">
window.onload=function(){
$(":input[tabindex='13']", $("#tblGrid2")).focus();
}
</script>