1.创建一个 <input> 元素必须同时设定 type 属性。因为微软规定 <input> 元素的 type 只能写一次。
jQuery 代码:
// 在 IE 中无效:
$("<input>").attr("type", "checkbox");
// 在 IE 中有效:
$("<input type='checkbox'>");
2.用jquery全选所有的input的写法。
$("[name='checkbox']").attr("checked",'true');//全选
$("[name='checkbox']").removeAttr("checked");//取消全选
3.nth-child(index/even/odd/equation)
匹配其父元素下的第N个子或奇偶元素。区别eq():
可以使用:
nth-child(even)
:nth-child(odd)
:nth-child(3n)
:nth-child(2)
:nth-child(3n+1)
:nth-child(3n+2)
如:在每个 ul 查找第 2 个li
HTML 代码:
<li>John</li>
<li>Karl</li>
<li>Brandon</li>
</ul>
<ul>
<li>Glen</li>
<li>Tane</li>
<li>Ralph</li>
</ul>
$("ul li:nth-child(2)")
4.jQuery判断一个元素是否为另一个元素的子元素(或者其本身)
比较简单的jQuery判断一个元素是否为另一个元素的子元素(或者其本身)的两个扩展:
使用起来也非常方便:
或者:
|