日期:2014-05-16  浏览次数:20330 次

怎么提到当前输入框的所引
<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>