本文实例讲述了jQuery中nextUntil()方法用法。分享给大家供大家参考。具体分析如下:
此函数查找指定元素之后所有的同辈元素,直到遇到匹配的那个元素为止,但不包括此匹配的元素。
语法结构一:
参数列表:
实例代码:
实例一:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://www.zzvips.com/" />
<title>服务器之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("li").eq(0).nextUntil(".jq").css("color","blue")
})
</script>
</head>
<body>
<div>
<ul>
<li>HTML专区</li>
<li class="js">Javascript专区</li>
<li>Div+Css专区</li>
<li class="jq">Jquery专区</li>
<li>ASP专区</li>
<li>JSP专区</li>
</ul>
</div>
</body>
</html>
实例二:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://www.zzvips.com/" />
<title>服务器之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("li").eq(0).nextUntil(".jq",".js").css("color","blue")
})
</script>
</head>
<body>
<div>
<ul>
<li>HTML专区</li>
<li class="js">Javascript专区</li>
<li>Div+Css专区</li>
<li class="jq">Jquery专区</li>
<li>ASP专区</li>
<li>JSP专区</li>
</ul>
</div>
</body>
</html>
语法结构二:
$(selector).closest(element, filter)
参数列表:
实例代码:
实例一:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://www.zzvips.com/" />
<title>服务器之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("li").eq(0).nextUntil(document.getElementById("jq")).css("color","blue")
})
</script>
</head>
<body>
<div>
<ul>
<li>HTML专区</li>
<li class="js">Javascript专区</li>
<li>Div+Css专区</li>
<li id="jq">Jquery专区</li>
<li>ASP专区</li>
<li>JSP专区</li>
</ul>
</div>
</body>
</html>
实例二:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://www.zzvips.com/" />
<title>服务器之家</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("li").eq(0).nextUntil(document.getElementById("jq"),".js").css("color","blue")
})
</script>
</head>
<body>
<div>
<ul>
<li>HTML专区</li>
<li class="js">Javascript专区</li>
<li>Div+Css专区</li>
<li id="jq">Jquery专区</li>
<li>ASP专区</li>
<li>JSP专区</li>
</ul>
</div>
</body>
</html>
希望本文所述对大家的jQuery程序设计有所帮助。