jQuery链式编程时修复断开的链

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#uone li').mouseover(function () {

//鼠标悬浮事件
$(this).css('backgroundColor', 'red').siblings('li').css('backgroundColor', '');


}).click(function () {
//单击事件
//有些方法是会破坏链式编程中返回的对象的,比如:next(),nextAll(),prev(),prevAll(),siblings(),无参数的:text()、val()、html()
//当链式编程的链被破坏以后可以通过end()方法修复。
$(this).prevAll().css('background-color', 'yellow').end().nextAll().css('backgroundColor', 'blue');
});
});
</script>
</head>
<body>
<ul id="uone">
<li>公牛</li>
<li>小牛</li>
<li>森林狼</li>
<li>开拓者</li>
</ul>
</body>
</html>

原文地址:https://www.cnblogs.com/jiangyunfeng/p/11808800.html