简体   繁体   中英

I need to use the “onchange” event inside @Html.RadioButton.[MVC]

I need to use the onchange event inside @Html.RadioButton.[MVC] I have a function 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";
        }
    }

I need to call this function on @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>

You can add the onchange event to 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM