jQuery實現(xiàn)獲取元素索引值index的方法
本文實例講述了jQuery實現(xiàn)獲取元素索引值index的方法。分享給大家供大家參考,具體如下:
<!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" /> <title>jquery獲取索引值</title> <style type="text/css"> *{margin:0; padding:0;} ul,li{list-style:none;} #wrap{width:980px; height:500px; overflow:hidden; margin:0 auto;} ul{width:200px; height:500px; float:left;} ul li{width:200px; height:100px; line-height:100px; text-align:center; font-size:16px; cursor:pointer;} #wrap div{width:700px; height:500px; float:right;} #btn0,.box0{background:#933;} #btn1,.box1{background:#09F;} #btn2,.box2{background:#93F;} #btn3,.box3{background:#F66;} #btn4,.box4{background:#3C0;} .box2,.box3,.box1,.box4{display:none;} #btn0.current,#btn1.current,#btn2.current,#btn3.current,#btn4.current{border:1px solid #000;} </style> <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(function(){ $("#btn li").click(function(){ $(this).addClass("current").siblings().removeClass("current"); var n=$("#btn li").index(this); $(".box"+n).show().siblings("div").hide(); }) }) </script> </head> <body> <div id="wrap"> <h2>點擊相應(yīng)的按鈕出現(xiàn)相對應(yīng)顏色的盒子</h2> <ul id="btn"> <li id="btn0" class="current">0</li> <li id="btn1">1</li> <li id="btn2">2</li> <li id="btn3">3</li> <li id="btn4">4</li> </ul> <div class="box0">第一個盒子</div> <div class="box1">第二個盒子</div> <div class="box2">第三個盒子</div> <div class="box3">第四個盒子</div> <div class="box4">第五個盒子</div> </div> </body> </html>
運行效果圖如下:
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery頁面元素操作技巧匯總》、《jQuery擴展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
相關(guān)文章
Jquery公告滾動+AJAX后臺得到數(shù)據(jù)
ajax得到值,用JQUERY綁定給對應(yīng)的UL.利用JQUERY的動畫來實現(xiàn)他們的滾動公告。2011-04-04jQuery ajax提交Form表單實例(附demo源碼)
這篇文章主要介紹了jQuery ajax提交Form表單的方法,結(jié)合實例分析了jQuery ajax操作實現(xiàn)表單提交的相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-04-04easyui datebox 時間限制,datebox開始時間限制結(jié)束時間,datebox截止日期比起始日期大的實現(xiàn)代碼
這篇文章主要介紹了easyui datebox 時間限制,datebox開始時間限制結(jié)束時間,datebox截止日期比起始日期大的實現(xiàn)代碼,需要的朋友參考下吧2017-01-01點擊表單提交時出現(xiàn)jQuery沒有權(quán)限的解決方法
擊表單提交的時候會出現(xiàn) jQuery 沒有權(quán)限,試了一下jquery自帶的json方式提交成功2014-07-07