【代码片段】jQuery测试兄弟元素集合
2013-03-05 19:25
375 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>第3章示例4</title> <style type="text/css"> body { width:780px; } div,p,h3,span { border:4px solid black; background-color:green; color:white; float:left; margin:6px; padding:5px; font:bold 14px/1 Arial,Helvetica,sans-serif; width:220px; display:block; } div p,div span { width:205px; border-width:2px; margin:5px 0; float:none; } p span { width:193px; border-width:1px;} h3 { margin-right:500px; } .clear { clear:both; } .relative { position:relative; } .highlight { background-color:gold; color:black; } form { clear:both; font:bold 14px/1 Arial,Helvetica,sans-serif; } button { font:bold 16px/1 Arial,Helvetica,sans-serif; margin:1px 3px; padding:2px; cursor:pointer; width:245px; } </style> <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){$("*").removeClass("highlight");}); $("#btn1").click(function(){$("h3").next(".clear").addClass("highlight");}); $("#btn2").click(function(){$("h3").next().addClass("highlight");}); $("#btn3").click(function(){$("h3").prev(".clear").addClass("highlight");}); $("#btn4").click(function(){$("h3").prev().addClass("highlight");}); $("#btn5").click(function(){$("h3").nextAll("[class]").addClass("highlight");}); $("#btn6").click(function(){$("h3").nextAll().addClass("highlight");}); $("#btn7").click(function(){$("h3").prevAll("[class]").addClass("highlight");}); $("#btn8").click(function(){$("h3").prevAll().addClass("highlight");}); $("#btn9").click(function(){$("h3").siblings("[class]").addClass("highlight");}); $("#btn10").click(function(){$("h3").siblings().addClass("highlight");}); $("#btn11").click(function(){$("h3").nextUntil(".relative").addClass("highlight");}); $("#btn12").click(function(){$("h3").nextUntil().addClass("highlight");}); $("#btn13").click(function(){$("h3").prevUntil(".clear").addClass("highlight");}); $("#btn14").click(function(){$("h3").prevUntil().addClass("highlight");}); $("button").click(function(){$("form").removeClass("highlight");}); }); </script> </head> <body> <div class="clear"> <div class="clear"> <p> <p> <span><span> </span></span> </p> </p> </div> </div> <div> <div> <p><p> </p></p> <p><p> </p></p> <p><p> </p></p> </div> </div> <div class="relative"> <div class="relative"> <span><span> </span></span> <span><span> </span></span> <span class="clear"><span class="clear"> </span></span> </div> </div> <h3 class="clear"><h3 class="clear"> </h3></h3> <div class="clear"> <div class="clear"> <p> <p> <span><span> </span></span> <span><span> </span></span> </p> </p> <p> <p> <span><span> </span></span> <span><span> </span></span> </p> </p> </div> </div> <div> <div> <p><p> </p></p> <p><p> </p></p> <p><p> </p></p> </div> </div> <div class="relative"> <div class="relative"> <span><span> </span></span> <span><span> </span></span> <span class="clear"><span class="clear"> </span></span> </div> </div> <form> <button type="button" id="btn1">$("h3").next(".clear")</button> <button type="button" id="btn2">$("h3").next()</button> <button type="button" id="btn3">$("h3").prev(".clear")</button> <button type="button" id="btn4">$("h3").prev()</button> <button type="button" id="btn5">$("h3").nextAll("[class]")</button> <button type="button" id="btn6">$("h3").nextAll()</button> <button type="button" id="btn7">$("h3").prevAll("[class]")</button> <button type="button" id="btn8">$("h3").prevAll()</button> <button type="button" id="btn9">$("h3").siblings("[class]")</button> <button type="button" id="btn10">$("h3").siblings()</button> <button type="button" id="btn11">$("h3").nextUntil(".relative")</button> <button type="button" id="btn12">$("h3").nextUntil()</button> <button type="button" id="btn13">$("h3").prevUntil(".clear")</button> <button type="button" id="btn14">$("h3").prevUntil()</button> </form> </body> </html>
相关文章推荐
- 【代码片段】jQuery测试后代元素集合
- 【代码片段】jQuery测试祖先元素集合
- 【代码片段】jQuery测试更多元素集合
- 【代码片段】jQuery测试基本过滤选择器
- 【代码片段】jQuery测试属性过滤选择器
- 【代码片段】jQuery测试层次选择器
- [置顶] 【scala 代码片段2】轻松入门scala--列表的操作以及集合元素映射
- 实用jquery代码片段集合
- jquery实用代码片段集合
- 实用jquery代码片段集合
- 【代码片段】jQuery测试内容过滤选择器
- 实用jquery代码片段集合
- jquery实用代码片段集合
- 【代码片段】jQuery测试基本选择器
- 【代码片段】jQuery测试表单选择器
- 10个 jQuery 小技巧/代码片段(未测试)
- 前端杂记(二)jquery实现元素隐藏的四个方法(附测试代码)
- 【代码片段】jQuery测试表单过滤选择器
- 工作中常用的js、jquery自定义扩展函数代码片段
- jquery 查找新建元素代码