onchange选择框 [英] onchange select box

查看:82
本文介绍了onchange选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有2个不同的选择框,其中包含相同数量的选项:

Say we have 2 different select boxes with the same number of options:

<select id="box1">
<option value="1" >1</option>
<option value="2" >2</option>
</select>

<select id="box2">
<option value="3" >3</option>
<option value="4" >4</option>
</select>

我们选择第一个框可以自动在第二个框中选择相同的选项号吗?如果可能的话没有jQuery。

Is it possible when we select the first box to select the same option number in the second box automatically? Without jQuery if possible.

更新:2个盒子的值是不同的!当我们选择box1的第一个值时,框2的值将自动为3!等等......

UPDATE: the values of 2 boxes are different! When we select the first value of box1 the box 2's value will automatically would be 3! and so on...

推荐答案

是的。将onChange属性添加到第一个选择,然后使用它来调用您在其他地方编写的javascript函数。

Yes. Add an onChange property to the first select, then use it to call a javascript function you have written elsewhere.

<select id="box1" onChange="changeBox2(this.selectedIndex);">
<option value="1" >1</option>
<option value="2" >2</option>
</select>

<select id="box2">
<option value="1" >1</option>
<option value="2" >2</option>
</select>

W3学校JavaScript活动

有关在JS中访问SELECT属性的示例

这篇关于onchange选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆