我想写一个js用于获取某个对象现在有一个input 在一个table里面<table id="tblGrid2">
<input tabindex=12/>
<input tabindex=13/>
</table>
如何通过this获取<input tabindex=13/>这个对象。类似如下,不过如下这个是不行的。
$(":input[tabindex=" + tabIndex + "]", this).focus();this 是table的对象。

解决方案 »

  1.   

    this关键字在对象内部使用才有意义。
    var tabIndex = 13;
    $(":input[tabindex='" + tabIndex + "']", $("#tblGrid2")).focus();
      

  2.   

    补全dom结构
    <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>
      

  3.   

    <table id="tblGrid2">
    <input tabindex=12/>
    <input tabindex=13/>
    </table>ff下生成的结构是这样的
    <input tabindex="12/">
    <input tabindex="13/">
    <table id="tblGrid2"> </table>
      

  4.   

    this在这里不行的楼主,测试了如下可行
    <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>