您现在的位置是:首页 > 电脑技术查询 > web开发

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

编辑:chaxungu时间:2022-10-02 23:20:27分类:web开发

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