jQuery中prevUntil()方法用法实例
作者:bea
本文实例讲述了jQuery中prevUntil()方法用法。分享给大家供大家参考。具体分析如下: 此函数查找匹配元素之前所有的同辈元素,直到遇到expr表达式、DOM元素或者jQuery元素匹配的那个元素为止。 可以使用可选的表达式对同辈元素集合进行筛选。 注意:祖先元素中并不包含expr表达式、DOM元素或者jQuery元素匹配的元素。 语法: 语法 一: 代码如下: $(selector).prevUntil(expr,filter) 参数列表:
本文实例讲述了jQuery中prevUntil()方法用法。分享给大家供大家参考。具体分析如下:
此函数查找匹配元素之前所有的同辈元素,直到遇到expr表达式、DOM元素或者jQuery元素匹配的那个元素为止。 可以使用可选的表达式对同辈元素集合进行筛选。
注意:祖先元素中并不包含expr表达式、DOM元素或者jQuery元素匹配的元素。
语法:
语法 一:
代码如下:
$(selector).prevUntil(expr,filter)
参数列表:
参数
描述
expr
可选。用于筛选祖先元素的表达式。
filter
可选。用于对取得的祖先元素集合进行筛选。
实例:
实例一:
代码如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http:///" />
<title></title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father div").prevUntil(".firstp").css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p class="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
实例二:
代码如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http:///" />
<title></title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father div").prevUntil(".firstp","span").css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p class="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
语法二:
代码如下:
$(selector).prevUntil(element,filter)
参数列表:
参数
描述
element
可选。用于筛选祖先元素的DOM元素或者jQuery元素。
filter
可选。用于对取得的祖先元素集合进行筛选。
实例:
实例一:
代码如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http:///" />
<title></title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father div").prevUntil(document.getElementById("firstp")).css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p id="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
实例二:
代码如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http:///" />
<title></title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father div").prevUntil(document.getElementById("firstp"),"span").css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p id="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
希望本文所述对大家的jQuery程序设计有所帮助。
有用 | 无用
此函数查找匹配元素之前所有的同辈元素,直到遇到expr表达式、DOM元素或者jQuery元素匹配的那个元素为止。 可以使用可选的表达式对同辈元素集合进行筛选。
注意:祖先元素中并不包含expr表达式、DOM元素或者jQuery元素匹配的元素。
语法:
语法 一:
代码如下:
$(selector).prevUntil(expr,filter)
参数列表:
参数
描述
expr
可选。用于筛选祖先元素的表达式。
filter
可选。用于对取得的祖先元素集合进行筛选。
实例:
实例一:
代码如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http:///" />
<title></title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father div").prevUntil(".firstp").css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p class="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
实例二:
代码如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http:///" />
<title></title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father div").prevUntil(".firstp","span").css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p class="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
语法二:
代码如下:
$(selector).prevUntil(element,filter)
参数列表:
参数
描述
element
可选。用于筛选祖先元素的DOM元素或者jQuery元素。
filter
可选。用于对取得的祖先元素集合进行筛选。
实例:
实例一:
代码如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http:///" />
<title></title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father div").prevUntil(document.getElementById("firstp")).css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p id="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
实例二:
代码如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http:///" />
<title></title>
<style type="text/css">
.father {
height:200px;
width:200px;
border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".father div").prevUntil(document.getElementById("firstp"),"span").css("color","blue")
})
</script>
</head>
<body>
<div class="father">
<p id="firstp">我是p元素</p>
<span>我是span元素</span>
<p>我是p元素</p>
<div>我是div元素</div>
</div>
</body>
</html>
希望本文所述对大家的jQuery程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 使用javascript实现简单的选项卡切换
- 14个有用的Jquery技巧分享
- jQuery中insertBefore()方法用法实例
- jQuery中insertAfter()方法用法实例
- jQuery中prependTo()方法用法实例
- 8个超实用的jQuery功能代码分享
- jQuery中appendTo()方法用法实例
- jQuery中append()方法用法实例
- jQuery中end()方法用法实例
- jQuery中contents()方法用法实例
- jQuery中andSelf()方法用法实例
- jQuery中add()方法用法实例
- javascript 动态创建表格
- javascript实现避免页面按钮重复提交
- Node.js 制作实时多人游戏框架
- jQuery之DOM对象和jQuery对象的转换与区别分析
- JavaScript结合AJAX_stream实现流式显示
- jQuery中siblings()方法用法实例
- 推荐5 个常用的JavaScript调试技巧