20190712-上午jQuery
——Javee
:nth-of-type(n) 选择器匹配属于父元素的特定类型的第 N 个子元素的每个元素.
n 可以是数字、关键词或公式。这里的n从1开始
p:nth-of-type(odd) /* 奇数 */
{
background:#ff0000;
}
p:nth-of-type(even) /* 偶数 */
{
background:#0000ff;
}
p:nth-of-type(3n+0) /* 公式 */
{
background:#ff0000;
}
ready和onload的区别:
-
jquery可以有多个ready,按顺序执行,onload只能有一个,如果有多个,后面的会覆盖前面的
-
ready只需要加载完所有的DOM就执行,onload要等整个页面加载完之后才执行(包括css、js等)
先来个小栗子:(全选/全取消)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../js/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function(){
$("#all").click(function(){
$(":checkbox:not(#all, #reverse)").attr("checked", this.checked);
});
});
</script>
</head>
<body>
全选/全取消<input type="checkbox" id="all"/><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
<input type="checkbox" /><br />
</body>
</html>