我需要检查一个检查箱的检查财产,并使用jQuery进行检查财产的操作。

例如,如果年龄检查框被检查,那么我需要显示一个文本框进入年龄,否则隐藏文本框。

但下列代码默认返回虚假:

如果($('#isAgeSelected').attr('checked')) { $("#txtAge").show(); } 其他 { $("#txtAge").hide(); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" id="isAgeSelected"/> <div id="txtAge" style="display:none"> 年龄 已选择 </div>

如何成功查询已检查的房地产?


当前回答

如何成功查询已检查的房地产?

检查箱 DOM 元素的检查属性将为您提供检查元素的状态。

考虑到您的现有代码,您可以这样做:

if(document.getElementById('isAgeSelected').checked) {
    $("#txtAge").show();
} else {
    $("#txtAge").hide();
}

但是,有一个更方便的方式来做到这一点,使用Toggle:

$('#isAgeSelected').click(功能() { $("#txtAge").toggle(this.checked); }; <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" id="isAgeSelected"/> <div id="txtAge" style="display:none"> 年龄是某种东西</div>

其他回答

使用此:

if ($('input[name="salary_in.Basic"]:checked').length > 0)

长度超过零,如果检查箱被检查。

如何成功查询已检查的房地产?

检查箱 DOM 元素的检查属性将为您提供检查元素的状态。

考虑到您的现有代码,您可以这样做:

if(document.getElementById('isAgeSelected').checked) {
    $("#txtAge").show();
} else {
    $("#txtAge").hide();
}

但是,有一个更方便的方式来做到这一点,使用Toggle:

$('#isAgeSelected').click(功能() { $("#txtAge").toggle(this.checked); }; <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" id="isAgeSelected"/> <div id="txtAge" style="display:none"> 年龄是某种东西</div>

一个选择器返回多个对象,它必须采取序列中的第一个项目:

// Collection
var chckremember = $("#chckremember");


// Result boolen
var ischecked=chckremember[0].checked;

使用:

<input type="checkbox" name="planned_checked" checked id="planned_checked"> Planned

$("#planned_checked").change(function() {
    if($(this).prop('checked')) {
        alert("Checked Box Selected");
    } else {
        alert("Checked Box deselect");
    }
});

$(“#planned_checked”).change(函数() { if($(this).prop('checked')) { alert(“Checked Box Selected”); } other { alert(“Checked Box deselect”); } }; <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <input type="checkbox" name="planned_checked" checked id="planned_checked">

我正在使用此:

 <input type="checkbox" id="isAgeSelected" value="1" /> <br/>
 <input type="textbox" id="txtAge" />

 $("#isAgeSelected").is(':checked') ? $("#txtAge").show() : $("#txtAge").hide();