单击单选按钮清除下拉选择
我有一组单选按钮。选择主要公司后,主要公司字段将被隐藏。我现在还想清除下拉选择。我该怎么做?
<p>
<label>Company Type:</label>
<label for="primary"><input onclick="javascript: $('#sec').hide('slow');" type="radio" runat="server" name="companyType" id="primary" checked />Primary</label>
<label for="secondary"><input onclick="javascript: $('#sec').show('slow');" type="radio" runat="server" name="companyType" id="secondary" />Secondary</label>
<div id="sec">
<label for="primary_company">Primary Company:</label>
<%= Html.DropDownList("primary_company", Model.SelectPrimaryCompanies, "** Select Primary Company **") %>
</div>
</p>
I have a set of radio buttons. When primary is selected, the Primary Company field is hidden. I would also like to at this time clear the drop down selection. How can I do this?
<p>
<label>Company Type:</label>
<label for="primary"><input onclick="javascript: $('#sec').hide('slow');" type="radio" runat="server" name="companyType" id="primary" checked />Primary</label>
<label for="secondary"><input onclick="javascript: $('#sec').show('slow');" type="radio" runat="server" name="companyType" id="secondary" />Secondary</label>
<div id="sec">
<label for="primary_company">Primary Company:</label>
<%= Html.DropDownList("primary_company", Model.SelectPrimaryCompanies, "** Select Primary Company **") %>
</div>
</p>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以清除选择(即选择第一个选项),如下所示:
You can clear the selection (that is, select the first option) like so:
您可以将 null 传递给 jQuery
val()
方法,作为清除下拉列表的好方法。You can pass null to the jQuery
val()
method as a nice way to clear a dropdown.要完全清除选择(以便甚至不选择第一个元素),您可以使用:
如果
#primary_company
是多选框,您可以使用:To clear the selection completely (so that not even the first element is selected) you could use:
If
#primary_company
is a multiple select box you could use:这是最适合我的捷径:
This is the best short way that works for me: