简体   繁体   English

检查是否在jQuery中选中了复选框

[英]Check whether the checkbox is checked or not in jquery

My view page: 我的查看页面:

<td>@Html.CheckBoxFor(m => m.CheckedStatus, new Dictionary<string, object> { { "id", "cbCheckedStatus7" }, { "name", "cbCheckedStatus" },{"class","onchange"} })  
</td>
<span id="spBlueCheckbox" style="display: none; color: blue;">    

Jquery: jQuery:

jQuery().ready(function domReady($) {
    if ($('#cbCheckedStatus7').is(':checked')) {
       $('#spBlueCheckbox').show();
    } else {
       $('#spBlueCheckbox').hide();
    }
});

if i check the checkbox, no action is taken place, i mean the span tag should be shown, when checkbox is checked. 如果我选中该复选框,则不会执行任何操作,这意味着在选中该复选框时,应该显示span标签。 Initially the span is not shown. 最初,不显示跨度。

You'll need an event handler for that 您需要一个事件处理程序

jQuery(function($) {
    $('#cbCheckedStatus7').on('change', function() {
        $('#spBlueCheckbox').toggle(this.checked);
    });
});

And where did you find that DOM ready handler? 在哪里找到DOM准备好的处理程序?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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