<1>
<!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="Jquery/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript">
//将所有div下的所有li的名字设为"哈哈",当点击的时候设为"我被点击了",其余没有点击的依然设为“哈哈”
$(function () {
var ss = $("div li"); //获取div下的所有li元素
$.each(ss, function () { //遍历获取到的这些li元素
$(this).html("哈哈"); //将当前遍历到li元素的html()设为"哈哈"
$(this).click(function () { //给当前遍历到的li元素添加click事件
$("div li").html("哈哈"); //将div下是所有li的html()设为"哈哈"
$(this).html("我被点击了"); //将当前点击的li的html()设为"我被点击了";
})
});
})
</script>
</head>
<body>
<div>
<ul>
<li></li>
<li></li>
</ul>
<ul>
<li></li>
<li></li>
</ul>
</div>
<div>
<ul>
<li></li>
<li></li>
</ul>
<ul>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
<2>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Jquery/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var inputs = $("input"); //获得或有的input表单
$.each(inputs, function () { //遍历这些表单
$(this).val("广州").css("background", "red"); //将当前遍历到的input表单的val设为广州,颜色设为红色
$(this).click(function () { //给当前遍历到的input表单添加click事件
//给当前点击的input表单的val设为深圳,颜色设为黄色,给当前点击的input表单的兄弟的val设为广州,颜色设为红色
$(this).val("深圳").css("background", "yellow").siblings().val("广州").css("background", "red");
})
})
})
</script>
</head>
<body>
<input type="button"/>
<input type="button"/>
<input type="button"/>
<input type="button"/>
</body>
</html>将所有div下的所有li的名字设为"哈哈",当点击的时候设为"我被点击了",其余没有点击的依然设为“哈哈”,布布扣,bubuko.com
将所有div下的所有li的名字设为"哈哈",当点击的时候设为"我被点击了",其余没有点击的依然设为“哈哈”
原文:http://blog.csdn.net/fanbin168/article/details/38182145