首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

2012-03-21 
怎么提到当前输入框的所引bodyscriptfunctionthis_index_input(obj){this_document.getElementsByNam

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

热点排行