![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
javascript中如使用onchange获得select的name及下标?
<selectname='stuname'onChange="cleartext();"><selectname='stuname'onChange="cleartext...
<select name='stuname' onChange="cleartext();">
<select name='stuname' onChange="cleartext();">
<select name='stuname' onChange="cleartext();">
<select name='stuname' onChange="cleartext();">
将select定义了成一维数组,问改变当前其一个select的值,如何获取stuname数组的下标? 展开
<select name='stuname' onChange="cleartext();">
<select name='stuname' onChange="cleartext();">
<select name='stuname' onChange="cleartext();">
将select定义了成一维数组,问改变当前其一个select的值,如何获取stuname数组的下标? 展开
1个回答
2013-10-30
展开全部
楼主,看代码吧.
<select name='stuname' onChange="cleartext(this);">
<option value="2">2</option>
<option value="1">1</option>
</select>
<select name='stuname' onChange="cleartext(this);">
<option value="2">2</option>
<option value="1">1</option>
</select>
<select name='stuname' onChange="cleartext(this);">
<option value="2">2</option>
<option value="1">1</option>
</select>
<select name='stuname' onChange="cleartext(this);">
<option value="2">2</option>
<option value="1">1</option>
</select>
<script>
function cleartext(){
var tt = document.getElementsByName("stuname");
for(i=0;i<tt.length;i++)
if(tt[i]==arguments[0])alert("你选择的是第"+(i+1)+"个!");
}
</script>
<select name='stuname' onChange="cleartext(this);">
<option value="2">2</option>
<option value="1">1</option>
</select>
<select name='stuname' onChange="cleartext(this);">
<option value="2">2</option>
<option value="1">1</option>
</select>
<select name='stuname' onChange="cleartext(this);">
<option value="2">2</option>
<option value="1">1</option>
</select>
<select name='stuname' onChange="cleartext(this);">
<option value="2">2</option>
<option value="1">1</option>
</select>
<script>
function cleartext(){
var tt = document.getElementsByName("stuname");
for(i=0;i<tt.length;i++)
if(tt[i]==arguments[0])alert("你选择的是第"+(i+1)+"个!");
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询