可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am having 2 Radio Buttons.(For Ex : ID and Name)..
<%=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.
回答1:
$(':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:
$(':radio[name=Emp]').change(function() { // read the value of the selected radio var value = $(this).val(); if (value == '2') { $('#MyDate').hide(); } });
回答2:
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...
Enjoy! :)