我需要在@ Html.RadioButton中使用“ onchange”事件。[MVC]

时间:2018-06-30 23:12:32

标签: javascript asp.net-mvc javascript-events

我需要在@ Html.RadioButton内使用“ onchange”事件。[MVC] 我有一个函数exp

 function FoncExamp() {
        if (document.ExpForm.K_T[0].checked == true) {
            document.getElementById("EK").style.display = "block";
            document.getElementById("YK").style.display = "none";
        }
        else {
            document.getElementById("EK").style.display = "none";
            document.getElementById("YK").style.display = "block";
        }
    }

我需要在@ html.radiobuttons上调用此函数

@using (Html.BeginForm(null, null, FormMethod.Post, new { name = "ExpForm" }))
{
<div class="container well">
    <div class="form-group row">
        <label class="col-md-2">EK @Html.RadioButton("K_T", "E_K")</label>
        <label class="col-md-2">YK @Html.RadioButton("K_T", "Y_K", new { @checked = true })</label>
    </div>

1 个答案:

答案 0 :(得分:0)

您可以将onchange事件添加到htmlAttributes

 <label class="col-md-2">EK @Html.RadioButton("K_T", "E_K", new { onchange = "FoncExamp(this)" })</label>
 <label class="col-md-2">YK @Html.RadioButton("K_T", "Y_K", new { @checked = true , onchange = "FoncExamp(this)"})</label>