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.

原文地址:https://www.cnblogs.com/rocky-fang/p/5259139.html