打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
jQuery中find函数(查找子元素)和end函数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
ul {
list-style-type: none;
width: 200px;
position: absolute;
left: 500px;
}
ul li {
margin-top: 10px;
cursor: pointer;
text-align: center;
font-size: 20px;
}
</style>
<script src="jquery-1.12.1.js"></script>
<script>
$(function () {
$("ul>li").mouseenter(function () {//鼠标进入事件
$(this).css("backgroundColor", "red").siblings("li").css("backgroundColor", "");
}).mouseleave(function () {//鼠标离开事件
//find函数-----寻找子元素中的... 参数可以是任意选择器
$(this).parent().find("li").css("backgroundColor", "");
}).click(function () {//点击事件
// $(this).prevAll("li").css("backgroundColor","yellow");
// $(this).nextAll("li").css("backgroundColor","blue");
//断链:对象调用方法之后,返回的已经不是当前的这个对象了,此时再调用方法,就出现了断链
//.end()方法是修复断链,恢复断链之前的状态,其实就是返回this,也就是指向最前面
//不推荐使用链式编程
$(this).prevAll("li").css("backgroundColor", "yellow").end().nextAll("li").css("backgroundColor", "blue");
});
});
</script>
</head>
<body>
<ul>
<li>青岛啤酒(TsingTao)</li>
<li>瓦伦丁(Wurenbacher)</li>
<li>雪花(SNOW)</li>
<li>奥丁格教士(Franziskaner)</li>
<li>科罗娜喜力柏龙(Paulaner)</li>
<li>嘉士伯Kaiserdom</li>
<li>罗斯福(Rochefort)</li>
<li>粉象(Delirium)</li>
<li>爱士堡(Eichbaum)</li>
<li>哈尔滨牌蓝带</li>
</ul>
</body>
</html>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
jQuery——jQuery选择器 ※
jQuery子元素伪类选择器
jquery基础用法总结
jquery单行滚动、批量多行滚动、文字图片翻屏
jQuery 选择器
12种jQuery代码性能优化方法 | 锐博
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服