Radio Button Change Event

倾然丶 夕夏残阳落幕 提交于 2019-12-08 17:24:52

问题


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)%>:&nbsp;
   <%: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! :)



来源:https://stackoverflow.com/questions/4202799/radio-button-change-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!