jquery checkbox checked

1.question:

   when first operate the checkbox with sentence like : 

        $("input[type=checkbox]").attr("checked",true);

        $("input[type=checkbox]").attr("checkec",false);

    it will succeed;

   but the second time , it will failed.why??

2.Cause:

  if the attribute name of the tag is belong to the tag(the html defined), the prop(name,value) method works,

  if the attribute name of the tag is custom , then attr(name, value) method works.

3. Solution:

   $("input[type=checkbox]").prop("checked",true);

  $("input[type=checkbox]").prop("checked",false);

  it works.

posted @ 2016-03-09 18:11  fangfan  阅读(346)  评论(0编辑  收藏  举报