通过jQuery添加checked属性

我正在使用以下小部件
http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/
它到目前为止工作得很好,但我需要一些帮助来添加属性.在使用Firebug时,我注意到只需单击复选框,checked属性就不会像我期望的那样出现.在我的代码中,我修改了小部件,我已经能够添加代码删除checked的属性.
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; }

代码删除checked的属性(如果在页面加载之前检查),但是当我尝试单击复选框以添加属性时(如果未在页面加载时检查),则没有任何反应.

感谢您的帮助,对不起我糟糕的编码感到抱歉.

解决方法

在jQuery中删除属性使用
this.removeAttr('checked');

并设置属性使用

this.attr('checked','checked');

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...