在html的checkbox里,选中的话会有属性checked="checked"。
我首先想到的写法是:
if($(this).attr("checked")=="checked"){}
但听有人说:jQuery的API手册上写,attr(name)的返回值是object。 所以,应该是
if($(this).attr("checked")==true){}
我在chrom下测试:
alert($(this).attr("checked"))
打印出的是checked,其他浏览器下的我没测试,单位了保险起见,这两种都写法也不纠结了;直接用了
if($(this).is(":checked")){}
搞定!
由于本人原博客已不再更新,本文为本文原博客备份文章
文章标签:
jquery