这可能已经在另一个帖子中得到了解答,但我无法找到解决方案......所以就这样了。
我已经使用flags定义了一个枚举:
[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
};
它由一个模型及其各自的助手使用。
[DisplayName("Infarct related vessel")]
[UIHint("FlagsEnum")]
public InfarctRelatedVessel MyInfarctRelatedVessel { get; set; }
视图相当简单。我显示了vessel属性的复选框列表,我有一个隐藏的div
我希望在&#34;其他&#34;的复选框时显示检查。
<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脚本来检测用户何时检查&#34;其他&#34;复选框并显示隐藏的div
思想?
答案 0 :(得分:0)
如果你想检测&#34;检查&#34;,你可以这样做:
$('#checkBox').click(function () {
if ($('#checkBox:checked').val() == 'true') {
$('#div').show();
}
});
答案 1 :(得分:0)
这应该符合您的要求:
$("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
}
});