繁体   English   中英

使用单选按钮重置下拉列表的值

[英]Reset value of dropdown list with radio button

我需要使用单选按钮重置下拉列表的值。 So when a certain radio button is selected, it will reset a specific dropdown list to the default selected="selected" option.

js和css如何做到这一点?

这应该将您的下拉菜单重置为第一个选项。 这是标记

<select id=foo>
  <option value=""></option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>
<input onclick="resetFoo();" type="radio" name="bar" value="bar">

这是 jQuery。

function doSomething {
    $("#foo option:first").attr("selected", true);
}
document.getElementById('select').selectedIndex = 0;

<input type="radio" onchange="doSomething()" />

假设这是您的第一个元素的代码

<select id=foo>
  <option value=""></option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>

你的单选按钮应该是这样的:

<input onclick="document.getElementById('foo').value = '';" type="radio" name="bar" value="bar">

onclick 事件下的值需要替换为下拉列表的默认值。

暂无
暂无

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

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