我正在使用以下小部件 http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/ 到目前为止效果很好,但我需要一些帮助来添加属性。在使用 Firebug 时,我注意到只需单击复选框,选中的属性不会像我期望的那样出现。在我的代码中,我修改了小部件,我已经能够添加代码以删除选中的属性。
this.removeAttribute(\'checked\'); this.checked=false;
如果事先检查过该项目。我已成功使用此代码
this.setAttribute(\'checked\', \'checked\'); this.checked=true;
如果页面加载时未选中该项目。
当我需要能够使用复选框上的两组代码时,我的问题就来了,我尝试了以下操作
onclick="if($(this).attr(\'checked\') == \'true\') { this.setAttribute(\'checked\', \'checked\'); this.checked=true; } else { this.removeAttribute(\'checked\'); this.checked=false; }
代码将删除选中的属性(如果在页面加载之前检查过),但是当我尝试单击复选框以添加属性(如果在页面加载时未选中)时,什么也没有发生。
感谢您的帮助,并为我糟糕的编码感到抱歉。