asp.net-mvc 单选按钮更改事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4202799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Radio Button Change Event
提问by RobinHood
I am having 2 Radio Buttons.(For Ex : ID and Name)..
我有 2 个单选按钮。(例如:ID 和名称)。
<%=Html.RadioButton("Emp","1")%>
<label>ID</label>
<%=Html.RadioButton("Emp","2")%>
<label>Name</label>
If i click the Name,
如果我点击名称,
<p>
<%:Html.LabelFor(m => m.MyDate)%>:
<%:Html.EditorFor(m => m.MyDate) %>
</p>
the above control should be visibled false..How to do this.
上面的控件应该是visibled false..如何做到这一点。
回答by Darin Dimitrov
$(':radio[value=2]').click(function() {
// Might need to adjust the selector here based
// on the field you would like to hide
$('#MyDate').hide();
});
or if you want to use the .change()
event:
或者如果您想使用该.change()
事件:
$(':radio[name=Emp]').change(function() {
// read the value of the selected radio
var value = $(this).val();
if (value == '2') {
$('#MyDate').hide();
}
});
回答by Developer
Use other approach...
使用其他方法...
<form method="post" id="ChangeEvent">
<%: Html.RadioButton("A1", "1", ViewData["IsSelected"] == "1", new { onclick = "document.getElementById('ChangeEvent').submit();" })%> Active
<%: Html.RadioButton("A1", "2", ViewData["IsSelected"] == "2", new { onclick = "document.getElementById('ChangeEvent').submit();" })%> Not Active
<%: Html.RadioButton("A1", "3", ViewData["IsSelected"] == "3", new { onclick = "document.getElementById('ChangeEvent').submit();" })%> All
</form>
Under code behind use Request.Form["A1"]to get selected value...
在后面的代码下使用Request.Form["A1"]来获取选定的值...
Enjoy! :)
享受!:)