简体   繁体   English

如果满足其他数据条件,请将隐藏复选框设置为true

[英]Set hidden checkbox to true if other data condition is met

I have a form that is divided up into a Kendo UI Panel Bar . 我有一个分为Kendo UI Panel Bar的表单。 In the first panel I have a field that when populated with any text, checks a checkbox that is currently not visible and is located within the collapsed panel below it. 在第一个面板中,我有一个字段,当该字段中填充任何文本时,选中一个当前不可见且位于其下方的折叠面板内的复选框。

My issue is that the checkbox doesn't check. 我的问题是该复选框未选中。 I've read some posts on how a checkbox is disabled when it isn't visible. 我已经阅读了一些文章,其中介绍了当复选框不可见时如何禁用它。 Is there a workaround for this? 有没有解决方法?

    function Validate(uid) {
    if ($("#SomeNumber_" + uid).val().length > 0) 
    {
        $("#MyCheckBox").attr('checked', true);  //This checkbox is display:none at the time this is set
        //Also tried these, but they didn't work:
        //$("#MyCheckBox").click();
        //var myCheckBox= document.getElementById("MyCheckBox");
        //myCheckBox.checked = true;
    }
}

Try $("#MyCheckBox").prop('checked', true); 试试$("#MyCheckBox").prop('checked', true);

I have a similar usecase and can attest that it is possible to check a hidden checkbox. 我有一个类似的用例,可以证明可以检查一个隐藏的复选框。

I think the correct way to use attr is $("#MyCheckBox").attr('checked', 'checked'); 我认为使用attr的正确方法是$("#MyCheckBox").attr('checked', 'checked');

Just tested the display none on a checkbox by dynamically changing it through a button. 只需通过按钮动态更改显示,就不会对复选框的显示进行任何测试。 It works with display none set. 它适用于未设置显示的情况。

http://jsfiddle.net/jmsessink/hcWf8/1/ http://jsfiddle.net/jmsessink/hcWf8/1/

The following will set the attr of your checkbox to 'checked' - 以下内容会将复选框的属性设置为“已选中”-

this - 这个 -

$('#MyCheckBox').attr('checked', true)

as well as 以及

$('#MyCheckBox').attr('checked', 'checked')

as well as 以及

document.getElementById('MyCheckBox').checked = true;

as well as 以及

document.getElementById('MyCheckBox').checked = 'checked';

*edit - updated jsfiddle version to show these four methods *编辑-更新了jsfiddle版本以显示这四种方法

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

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