我有2个收音机按钮。(例如:ID和姓名)..
<%=Html.RadioButton("Emp","1")%>
<label>ID</label>
<%=Html.RadioButton("Emp","2")%>
<label>Name</label>
如果我点击名称,
<p>
<%:Html.LabelFor(m => m.MyDate)%>:
<%:Html.EditorFor(m => m.MyDate) %>
</p>
上面的控件应该是假的。如何做到这一点。
答案 0 :(得分:14)
$(':radio[value=2]').click(function() {
// Might need to adjust the selector here based
// on the field you would like to hide
$('#MyDate').hide();
});
或者如果您想使用.change()
事件:
$(':radio[name=Emp]').change(function() {
// read the value of the selected radio
var value = $(this).val();
if (value == '2') {
$('#MyDate').hide();
}
});
答案 1 :(得分:2)
使用其他方法......
<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>
在代码背后使用 Request.Form [“A1”] 来获取所选值...
享受! :)