初探jQuery

封装一个函数
html部分
<ul>
<li id="items1">选项1</li>
<li id="items2">选项2</li>
<li id="items3">选项3</li>
<li id="items4">选项4</li>
<li id="items5">选项5</li>
</ul>
js部分
function getSilblings(node){
var allChildren = node.parentNode.children;
//对象表示法
var array ={length:0};
// 数组表示法
//var array = [];

for(let i = 0;i<allChildren.length;i++){
if(allChildren[i] !== node){
//array[array.length] = allChildren[i];
//0 = items1
//1 = items2
//2 = items3
//3 = items5
array[array.length] = allChildren[i];
// 为什么不用i 因为用i会从中间跳过一个 序号就不是一一对应的了
// array[i] = allChildren[i];
array.length+=1;

}
}
console.log(array);
}
console.log(getSilblings(items4));
代码展示


image.png

=== 和 ==
为什么不用== 而是用=== 因为==太难了 学不会 非常容易出错
下面是x==y的真值表 左边表示X的值 上边表示Y的值 绿色的点表示true 白色的点表示false

===和==区别.png

===比较 NaN 不等于 NaN


===.png

给items3 添加一个class 用数组展示
html代码块
[图片上传中...(image.png-ca54e0-1546501856469-0)]

js代码块


image.png

hash表示法


image.png

封装成一个函数


image.png

优化代码


image.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容