Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 确定在MVC 5(editorfor)复选框列表中选中的复选框_Jquery_Asp.net Mvc_Checkbox_Enum Flags - Fatal编程技术网

Jquery 确定在MVC 5(editorfor)复选框列表中选中的复选框

Jquery 确定在MVC 5(editorfor)复选框列表中选中的复选框,jquery,asp.net-mvc,checkbox,enum-flags,Jquery,Asp.net Mvc,Checkbox,Enum Flags,这可能已经在另一个线程中得到了回答,但我找不到解决方案。。。就这样 我定义了一个带有标志的枚举: [Flags] public enum InfarctRelatedVessel { [Description("Left anterior descending")] LEFT_ANTERIOR_DESC = 1<<0, [Description("Right coronary")] RIGHT_CORONARY = 1<<1,

这可能已经在另一个线程中得到了回答,但我找不到解决方案。。。就这样

我定义了一个带有标志的枚举:

 [Flags]
 public enum InfarctRelatedVessel
 {
     [Description("Left anterior descending")]
     LEFT_ANTERIOR_DESC = 1<<0,
     [Description("Right coronary")]
     RIGHT_CORONARY = 1<<1,
     [Description("Left circumflex")]
     LEFT_CIRCUMFLEX = 1<<2,
     [Description("Left main")]
     LEFT_MAIN = 1<<3,
     [Description("Other")]
     OTHER = 1<<4
 };
观点相当简单。我显示Vessers属性的复选框列表,并且我有一个隐藏的div,当选中other的复选框时,我希望显示该div

<div class="form-group">
    @Html.LabelFor(model => model.MyInfarctRelatedVessel, new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EditorFor(model => model.MyInfarctRelatedVessel)
        @Html.ValidationMessageFor(model => model.MyInfarctRelatedVessel)

        <input type="hidden" id="InfarctVessels" />
    </div>
</div>
<div class="well well-sm" id="DivOtherVessel">
    @Html.LabelFor(model => model.MyOtherInfarctRelatedVessel, new { @class = "control-label col-md-4" })
    <div class="col-md-8">
        @Html.EditorFor(model => model.MyOtherInfarctRelatedVessel)
        @Html.ValidationMessageFor(model => model.MyOtherInfarctRelatedVessel)
    </div>
</div>
我正在努力使用jquery脚本,该脚本将检测用户何时选中其他复选框并显示隐藏的div


想法?

如果要检测支票,可以执行以下操作:

$('#checkBox').click(function () {
    if ($('#checkBox:checked').val() == 'true') {
        $('#div').show();
    }
});

这应该满足您的要求:

$("input:checkbox[name='@Html.NameFor(m => m.MyOtherInfarctRelatedVessel)']").change(function(){
    var anyChecked = false;
    $("input:checkbox[name='@Html.NameFor(m => m.MyOtherInfarctRelatedVessel)']").each(function(){
        if($(this).is(":checked")) anyChecked = true;
    });
    if(anyChecked){
        // show hidden div
    }
});

顺便说一句,我假设您正在使用Razor和至少MVC4作为NameFor扩展方法,否则您可以硬编码名称。谢谢。正如您所设想的,我正在使用MVC5和razor,但我不得不使用硬编码名称:S
$("input:checkbox[name='@Html.NameFor(m => m.MyOtherInfarctRelatedVessel)']").change(function(){
    var anyChecked = false;
    $("input:checkbox[name='@Html.NameFor(m => m.MyOtherInfarctRelatedVessel)']").each(function(){
        if($(this).is(":checked")) anyChecked = true;
    });
    if(anyChecked){
        // show hidden div
    }
});