Select all items in checkbox group with CSJS?

回眸只為那壹抹淺笑 提交于 2019-12-12 03:35:43

问题


I am able to select all of the items in a checkbox group with SSJS by simply setting the component's value.

But how would I do this in CSJS?


回答1:


Assuming that the name of your check box group is checkBoxGroup this code snippet of check all checkbox should do the trick for you.

<xp:checkBox text="Check all" id="chkCheckAll">
    <xp:eventHandler event="onclick" submit="false">
        <xp:this.script><![CDATA[dojo.query("input[name=\"#{id:checkBoxGroup}\"]").forEach(
    function(node) {
        node.checked = document.getElementById("#{id:chkCheckAll}").checked;
    }
)]]></xp:this.script>
    </xp:eventHandler>
</xp:checkBox>



回答2:


You select them with dojo.query and set the selected property to true. You need to check: every box will have its own ID, but the beginning of it is the same -or- you use a class. Or you look for the first and then select all siblings.

The strategy depends on your application's needs.

Check the dojo.query documentation for your options.




回答3:


this is how you do it in jquery

$("[name$=checkBoxGroup1]").attr("checked",true)



回答4:


Simplifying Naveen's answer, this worked great for me:

dojo.query("input[name=\"#{id:checkBoxGroup1}\"]").forEach( function(node) {
        node.checked = true; 
    });


来源:https://stackoverflow.com/questions/12963732/select-all-items-in-checkbox-group-with-csjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!