mvc 4单击@Html.radiobutton后如何调用javascript函数

mvc 4单击@Html.radiobutton后如何调用javascript函数,javascript,asp.net-mvc-4,Javascript,Asp.net Mvc 4,视图有: <div Monthly @Html.RadioButtonFor(m => m.DDPaymentOption, "Monthly", true) Yearly @Html.RadioButtonFor(m => m.DDPaymentOption, "Yearly", true) </div> 不点击功能使用此代码 $("input[type=radio]").change(function () { var Selecte

视图有:

<div Monthly @Html.RadioButtonFor(m => m.DDPaymentOption, "Monthly", true) 
     Yearly  @Html.RadioButtonFor(m => m.DDPaymentOption, "Yearly", true)  
</div>
不点击功能

使用此代码

$("input[type=radio]").change(function () {
    var Selectedvalue = $(this).val();
    var isDiv = $("#instalmentScheduleDiv");
    if (Selectedvalue == "Yearly")
    {
        isDiv.hide();
    } else {
       isDiv.show();
    }
});
$('#DDPaymentOption').click(function(){  
         if($(this).val()=='Yearly') 
         {
             $('#instalmentScheduleDiv').addClass('HideDiv');
         }
 });
如果使用HideDiv类隐藏div,可以使用jquery方法显示或隐藏div元素,如

$('#instalmentScheduleDiv').hide(); // to hide the element
和/或

    $('#instalmentScheduleDiv').show(); // to show the element

所有的功劳都归于:codingbiz

这就是你能做到的

function updatePostID(val)
{
    document.getElementById('PostID').value = val;

    //and probably call document.forms[0].submit();
}
然后为posted创建一个隐藏字段或其他控件

@Html.Hidden("PostID", Model.addcomment.PostID)
//OR
@Html.HiddenFor(model => model.addcomment.PostID)

这是一个JSFIDLE解决方案,现在看看你的浏览器,你的html看起来怎么样?与此示例进行比较并纠正错误。
@Html.Hidden("PostID", Model.addcomment.PostID)
//OR
@Html.HiddenFor(model => model.addcomment.PostID)