当前位置: 代码迷 >> JavaScript >> 如何提到当前输入框的所引
  详细解决方案

如何提到当前输入框的所引

热度:112   发布时间:2012-03-21 13:33:15.0
怎么提到当前输入框的所引
<body>
<script>
function   this_index_input(obj){
this_=document.getElementsByName(obj.name);
alert(this_.index);
}
</script>
<input   type= "text "   name= "textfield[] "   onClick= "this_index_input(this) "> <input   type= "text "   name= "textfield[] "   onClick= "this_index_input(this) "> <input   type= "text "   name= "textfield[] "   onClick= "this_index_input(this) "> <input   type= "text "   name= "textfield[] "   onClick= "this_index_input(this) ">
</body>

------解决方案--------------------
<script>
function this_index_input(obj){
var list = document.form1.elements[ "textfield[] "];
for(var i=0;i <list.length;i++){
if (list[i]==obj){
alert(i);
break;
}
}

}
</script>
<form name= "form1 ">
<input type= "text " name= "textfield[] " onClick= "this_index_input(this) "> <input type= "text " name= "textfield[] " onClick= "this_index_input(this) "> <input type= "text " name= "textfield[] " onClick= "this_index_input(this) "> <input type= "text " name= "textfield[] " onClick= "this_index_input(this) ">
</form>
  相关解决方案