JS设置多个Select选框内容同步

调用Select选框的onchange()函数,选框内容发生改变,即触发setSelect()函数,然后对其余选框动态赋值,即可,代码如下:

<html>
<head>
<script type="text/javascript">
function setSelect()
{
document.getElementById("mySelect1").value=document.getElementById("mySelect").value;
document.getElementById("mySelect2").value=document.getElementById("mySelect").value;
}
</script>
</head>
<body>

<form>

<select name="mySelect" id="mySelect" onchange="setSelect()">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<select name="mSelect" id="mySelect1" >
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
<select name="mSelect" id="mySelect2" >
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>

</body>
</html>

打赏此文

如果您觉得本站的内容对您有所帮助,您可以扫描下面的二维码小额支付请我喝杯茶,感谢!打赏记录
支付宝
微信
承诺:凡打赏捐助的朋友,留言备注自己的邮箱,在打赏捐助时间点的6个月内,本站会每周邮件推送原创专业技术博文,供大家学习和参考!

留下评论

All fields marked (*) are required