简体   繁体   English

Javascript:如果选择了下拉菜单,请选择单选按钮

[英]Javascript: Select Radio Button if a Dropdown is Selected

I'm wondering how I can use Javascript to accomplish the following: 我想知道如何使用Javascript完成以下任务:

I have an input area with five dropdownlists, and each one has a corresponding radio button. 我有一个带有五个下拉列表的输入区域,每个都有一个相应的单选按钮。 When a dropdownlist is clicked to make a selection, I would like the radio button paired with it to become checked right then. 单击下拉列表进行选择时,我希望与其配对的单选按钮会立即被选中。 Any help would be appreciated, thanks! 任何帮助,将不胜感激,谢谢!

Its kind of simple really. 真的很简单。 Here is a small code for you. 这是给您的一小段代码。 ID the 5 listboxes as "sel1", "sel2" ,... ID the 5 radio buttons "rad1", rad2,.. Make sure the radio buttons have same name though! 标识5个列表框为“ sel1”,“ sel2”,...。标识5个单选按钮“ rad1”,rad2..。请确保单选按钮具有相同的名称!

Next, put this function in as a javascrip: 接下来,将此函数作为javascrip放入:

function makeSelection(radioid){
document.getElementById(radioid).checked=true;
}

In the select boxes, attach onchanged listeners: ie; 在选择框中,附加已更改的侦听器:

<select ... onchange="makeSelection('rad1');" >.. for the 1st select box,
<select ... onchange="makeSelection('rad2');" >.. for the 2ns select box, etc.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM