简体   繁体   English

使用SelectAll函数的复选框样式

[英]Checkbox Styling with SelectAll Function

Was styling the checkboxes of my webpage with jquery using the tutorial here 使用此处的教程使用jQuery对我的网页的复选框进行样式设置

But i realized that I could not do SelectAll checkbox that will select all the checkboxes in my list. 但是我意识到我无法执行SelectAll复选框,该复选框将选择列表中的所有复选框。 It works in the backend (the checkboxes are selected) but it does not show in my page. 它在后端工作(选中了复选框),但未在我的页面中显示。

Added a demo to show my problem. 添加了一个演示以显示我的问题。 May need to port to your system to test it out 可能需要移植到您的系统进行测试

Demo 演示版

what can I add to the jQuery Custom Radio-buttons and Checkbox javascript file in the to achieve the select all checkbox function 我可以在jQuery Custom单选按钮和Checkbox javascript文件中添加什么以实现全选复选框功能

Thank you! 谢谢!

You can try this FIDDLE : 您可以尝试以下FIDDLE

$(function () {
    var $chbxs = $('.checkbox');
    $('#sel_all_lbl').toggle(
        function() {
            $chbxs.css('background-position', '50% -50px');
            $('#checkboxall .truefalse').prop('checked', true);
        },
        function() {
            $chbxs.css('background-position', '50% 0px');
            $('#checkboxall .truefalse').prop('checked', false);
        }
    );
});

What I've done? 我做了什么? First, in your fiddle you need to correct some syntax errors, then add a plugin code to the DOM, and you scripts to the script panel, so they will fire when DOM is ready. 首先,您需要纠正一些语法错误,然后将插件代码添加到DOM,然后将脚本添加到脚本面板,以便在DOM准备就绪时触发它们。 (This is all about jsFiddle, so you to understand how it works) (这全都是关于jsFiddle的,因此您了解它是如何工作的)

About actually your code, you attached click-handlers ( .toggle() ) to the checkbox element. 关于您的代码,实际上是将单击处理程序( .toggle() )附加到复选框元素。 But click event does not fire on it. 但是click事件不会触发。 Script simply changed the property of the checkbox, but there is no click. 脚本只是更改了复选框的属性,但是没有单击。 So you need to attach these handler to the element wish user actually clicks, that is square icon. 因此,您需要将这些处理程序附加到希望用户实际点击的元素上,即方形图标。 (I added an id="sel_all_lbl" to it) (我在其中添加了id="sel_all_lbl"

尝试在全选复选框上使用事件处理,然后从javascript中手动选中所有复选框。

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

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