您的位置:首页 > Web前端 > JQuery

jQuery学习06---节点遍历,评分控件还有简单选择器

2013-06-19 23:31 537 查看
节点遍历

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=GBK">
<link rel="stylesheet" type="text/css" href="table.css">
<title></title>
<script src="../jquery-1.8.2.js" type="text/javascript"></script>
<style type="text/css">
</style>
<script type="text/javascript">
$(function()
{
//next()查找下一个紧邻的节点next("#x")查找下一个紧邻的id为x的节点
$("#d4").next().css("background-color","red");
//nextAll()之后的所有节点.之后的所有的div标签nextAll("div")
$("#d4").nextAll().css("background-color","red");
//之前的紧邻节点
$("#d4").prev().css("background-color","red");
//之前的所有节点
$("#d4").prevAll().css("background-color","red");
//查找所有的兄弟节点
$("#d4").siblings().css("background-color","red");
//查找本节点和本节点之后的节点,end()返回上一次jQuery对象被破坏之前的状态
$("#d4").nextAll().css("background-color","red").end().css("background-color","red");
$("#d4").nextAll().andSelf().css("background-color","red");
$("#d4").nextAll().andSelf().end().css("background-color","red");
});
</script>
</head>
<body>
<div>11111111</div>
<div>22222222</div>
<div>33333333</div>
<div id="d4">44444444</div>
<p>55555555</p>
<div>66666666</div>
<div>77777777</div>
<div>88888888</div>
<div>99999999</div>
</body>
</html>


评分控件

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=GBK">
<link rel="stylesheet" type="text/css" href="table.css">
<title></title>
<script src="../jquery-1.8.2.js" type="text/javascript"></script>
<style type="text/css">
</style>
<script type="text/javascript">
$(function()
{
$("#rating span").mouseover(function()
{
//$(this).prevAll.andSelf().text("★");
//$(this).nextAll.text("★");
$(this).prevAll().andSelf().text("★").end().end().nextAll().text("☆");
});
});
</script>
</head>
<body>
<div id="rating">
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
<span>☆</span>
</div>
</body>
</html>


简单选择器

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=GBK">
<link rel="stylesheet" type="text/css" href="table.css">
<title></title>
<script src="../jquery-1.8.2.js" type="text/javascript"></script>
<style type="text/css">
</style>
<script type="text/javascript">
$(function()
{
//第一个
//$("input:first").css("background-color","red");
//最后一个
//$("input:last").css("background-color","red");
//排除id为t1和class为myClass的
//$("input:not(.myClass):not(#t1)").css("background-color","red");
//odd是奇数,even是偶数但下标从0开始
//$("input:odd").css("background-color","red");
//第三项
//$("input:eq(2)").css("background-color","red");
//小于3的项
//$("input:lt(3)").css("background-color","red");
//大于3的项
//$("input:gt(3)").css("background-color","red");
//最后3个
var num = $("input").length-4;
$("input:eq("+num+")").nextAll().css("background-color","red");
});
</script>
</head>
<body>
<input id="t1" type="text" /><br />
<input type="text" /><br />
<input type="text" /><br />
<input class="myClass" type="text" /><br />
<input class="myClass" type="text" /><br />
<input type="text" /><br />
<input type="text" /><br />
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: