<tr> <td> 
                        <span id="GridView1_ctl03_chinese"> 日本人 </span> 
                    </td> <td> 
                        <span id="GridView1_ctl03_type">名 </span> 
                    </td> <td> 
                        <input name="GridView1$ctl03$japanese" type="text" id="GridView1_ctl03_japanese" onkeydown="textboxfocus('this')" style="width:150px;" /> 
                    </td> 
</tr> <tr> 
<td> 
                        <span id="GridView1_ctl04_chinese"> 韩国人 </span> 
                    </td> <td> 
                        <span id="GridView1_ctl04_type">名 </span> 
                    </td> <td> 
                        <input name="GridView1$ctl04$japanese" type="text" id="GridView1_ctl04_japanese"  onkeydown="textboxfocus('this')" style="width:150px;" /> 
                    </td> 
</tr> 
我想要每个text触发onkeydown事件的时候,自动把焦点移动到下一个text

解决方案 »

  1.   

    先用jquery把该页面所有type="text"的控件查到组成一个列表,然后循环一下。如果是最后一个text,就不需要移动焦点了。
      

  2.   

    function textboxfocus(obj)
    {
    $(":text",$(obj).parent().parent().next()).focus();
    }
    另:onkeydown="textboxfocus('this')"  =>  onkeydown="textboxfocus(this)" 
      

  3.   

    更通用的不依赖于页面结构的做法是function textboxfocus(obj)
    {
    var texts = $(":text");
    $.each(texts,function(idx,text){
    if(text == obj){
    texts[idx+1].focus();
    return false;
    }
    });
    }