<html>
<body>
<form name="nasami">
<input tabindex="30" value="1" type="text" >
<input tabindex="20" value="2" type="text" >
<input tabindex="10" value="3" type="text" >
<input tabindex="60" value="4" type="text" >
<input tabindex="50" value="5" type="text" >
<input tabindex="40" value="6" type="text" >
<input type="botton" value="aa">
</form>
</body>
</html>
我想写一个共通当我点击按钮处理完相关业务后吧光标放在页面上tabIndex值最小的控件上
用javascript怎么来写 
请教各位大侠

解决方案 »

  1.   

    遍历,就像冒泡法排序,但你只需要比较一遍就OK了
    示例:function MinFocus()
    {
       var eles = document.getElementsByTagName("input");
       var focusObj = null;
       for(var i=0;i<eles.length;i++)
       {
          if(eles[i].getAttribute("tabindex"))
          {
              if(focusObj)
              {
         var ei = parseInt(eles[i].getAttribute("tabindex"));
                 var fi = parseInt(focusObj.getAttribute("tabindex"));
     if(ei<fi)
     focusObj = eles[i];
              }
      else
                 focusObj = eles[i];
          }
       }
       if(focusObj)
       focusObj.focus();
    }
      

  2.   

    如果还有图片和label怎么办?
      

  3.   

    那就取document.all,所有元素分析,
    先判断ele.tagname 在 img,label之中。