单选按钮更改事件

时间:2010-11-17 08:50:12

标签: asp.net-mvc asp.net-mvc-2

我有2个收音机按钮。(例如:ID和姓名)..

  <%=Html.RadioButton("Emp","1")%>
  <label>ID</label>
  <%=Html.RadioButton("Emp","2")%>
  <label>Name</label>    

如果我点击名称,

<p>
   <%:Html.LabelFor(m => m.MyDate)%>:&nbsp;
   <%:Html.EditorFor(m => m.MyDate) %>
</p>

上面的控件应该是假的。如何做到这一点。

2 个答案:

答案 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”] 来获取所选值...

享受! :)