jQuery教程
一、簡(jiǎn)介
定義
jQuery創(chuàng)始人是美國(guó)John Resig,是優(yōu)秀的Javascript框架;
jQuery是一個(gè)輕量級(jí)、快速簡(jiǎn)潔的javaScript庫(kù)。
jQuery對(duì)象
jQuery產(chǎn)生的對(duì)象時(shí)jQuery獨(dú)有的,只能自己調(diào)用
書(shū)寫(xiě)規(guī)則
支持鏈?zhǔn)讲僮?#xff1b;
在變量前加"$"符號(hào)(var $variable = jQuery?對(duì)象);
注:此規(guī)定并不是強(qiáng)制要求。
二、尋找元素
選擇器
基本選擇器、層級(jí)選擇器、屬性選擇器 ?與CSS類似
#id .class element element[屬性名=值]基本篩選器
$('li:first') //第一個(gè)元素 $('li:last') //最后一個(gè)元素 $("tr:even") //索引為偶數(shù)的元素,從 0 開(kāi)始 $("tr:odd") //索引為奇數(shù)的元素,從 0 開(kāi)始 $("[href='#']") //所有 href 屬性的值等于 "#" 的元素 $("[href!='#']" //所有 href 屬性的值不等于 "#" 的元素 $("[href$='.jpg']") //所有 href 屬性的值包含以 ".jpg" 結(jié)尾的元素 $("tr:eq(1)") //給定索引值的元素$("tr:gt(0)") //大于給定索引值的元素
$("tr:lt(2)") //小于給定索引值的元素
$(":focus") //當(dāng)前獲取焦點(diǎn)的元素
$(":animated") //正在執(zhí)行動(dòng)畫(huà)效果的元素
$(":enabled") //所有激活的 input 元素 $(":enabled") //所有禁用的 input 元素 $(":selected") //所有被選取的 input 元素
$(":checked") //所有被選中的 input 元素
內(nèi)容選擇器
$("div:contains('nick')") //包含nick文本的元素 $("td:empty") //不包含子元素或者文本的空元素 $("div:has(p)") //含有選擇器所匹配的元素 $("td:parent") //含有子元素或者文本的元素表單對(duì)象屬性
$("input:checked") //所有選中的元素$("select option:selected") //select中所有選中的option元素篩選器
過(guò)濾
$("p").eq(0) //當(dāng)前操作中第N個(gè)jQuery對(duì)象,類似索引 $('li').first() //第一個(gè)元素 $('li').last() //最后一個(gè)元素 $(this).hasClass("test") //元素是否含有某個(gè)特定的類,返回布爾值 $('li').has('ul') //包含特定后代的元素查找
$("div").children() //div中的每個(gè)子元素,第一層 $("div").find("span") //div中的包含的所有span元素,子子孫孫 $("p").next() //緊鄰p元素后的一個(gè)同輩元素 $("p").nextAll() //p元素之后所有的同輩元素 $("#test").nextUntil("#test2") //id為"#test"元素之后到id為'#test2'之間所有的同輩元素,掐頭去尾 $("p").prev() //緊鄰p元素前的一個(gè)同輩元素 $("p").prevAll() //p元素之前所有的同輩元素 $("#test").prevUntil("#test2") //id為"#test"元素之前到id為'#test2'之間所有的同輩元素,掐頭去尾 $("p").parent() //每個(gè)p元素的父元素 $("p").parents() //每個(gè)p元素的所有祖先元素,body,html $("#test").parentsUntil("#test2") //id為"#test"元素到id為'#test2'之間所有的父級(jí)元素,掐頭去尾 $("div").siblings() //所有的同輩元素,不包括自己三、屬性操作
基本屬性操作
$("img").attr("src"); //返回文檔中所有圖像的src屬性值 $("img").attr("src","test.jpg"); //設(shè)置所有圖像的src屬性 $("img").removeAttr("src"); //將文檔中圖像的src屬性刪除 $("input[type='checkbox']").prop("checked", true); //選中復(fù)選框 $("input[type='checkbox']").prop("checked", false); $("img").removeProp("src"); //刪除img的src屬性CSS類
$("p").addClass("selected"); //為p元素加上 'selected' 類 $("p").removeClass("selected"); //從p元素中刪除 'selected' 類 $("p").toggleClass("selected"); //如果存在就刪除,否則就添加HTML代碼/文本/值
$('p').html(); //返回p元素的html內(nèi)容 $("p").html("Hello <b>nick</b>!"); //設(shè)置p元素的html內(nèi)容 $('p').text(); //返回p元素的文本內(nèi)容 $("p").text("nick"); //設(shè)置p元素的文本內(nèi)容 $("input").val(); //獲取文本框中的值 $("input").val("nick"); //設(shè)置文本框中的內(nèi)容?四、CSS操作
?? 樣式
$("p").css("color"); //訪問(wèn)查看p元素的color屬性 $("p").css("color","red"); //設(shè)置p元素的color屬性為red $("p").css({ "color": "red", "background": "yellow" }); //設(shè)置p元素的color為red,background屬性為yellow(設(shè)置多個(gè)屬性要用{}字典形式)位置
$('p').offset() //元素在當(dāng)前視口的相對(duì)偏移,Object {top: 122, left: 260} $('p').offset().top $('p').offset().left $("p").position() //元素相對(duì)父元素的偏移,對(duì)可見(jiàn)元素有效,Object {top: 117, left: 250} $(window).scrollTop() //獲取滾輪滑的高度 $(window).scrollLeft() //獲取滾輪滑的寬度 $(window).scrollTop('100') //設(shè)置滾輪滑的高度為100尺寸
$("p").height(); //獲取p元素的高度 $("p").width(); //獲取p元素的寬度 $("p:first").innerHeight() //獲取第一個(gè)匹配元素內(nèi)部區(qū)域高度(包括補(bǔ)白、不包括邊框) $("p:first").innerWidth() //獲取第一個(gè)匹配元素內(nèi)部區(qū)域?qū)挾?包括補(bǔ)白、不包括邊框) $("p:first").outerHeight() //匹配元素外部高度(默認(rèn)包括補(bǔ)白和邊框) $("p:first").outerWidth() //匹配元素外部寬度(默認(rèn)包括補(bǔ)白和邊框) $("p:first").outerHeight(true) //為true時(shí)包括邊距五、文檔處理
?內(nèi)部插入
$("p").append("<b>nick</b>"); //每個(gè)p元素內(nèi)后面追加內(nèi)容 $("p").appendTo("div"); //p元素追加到div內(nèi)后 $("p").prepend("<b>Hello</b>"); //每個(gè)p元素內(nèi)前面追加內(nèi)容 $("p").prependTo("div"); //p元素追加到div內(nèi)前外部插入
$("p").after("<b>nick</b>"); //每個(gè)p元素同級(jí)之后插入內(nèi)容 $("p").before("<b>nick</b>"); //在每個(gè)p元素同級(jí)之前插入內(nèi)容 $("p").insertAfter("#test"); //所有p元素插入到id為test元素的后面 $("p").insertBefore("#test"); //所有p元素插入到id為test元素的前面替換
$("p").replaceWith("<b>Paragraph. </b>"); //將所有匹配的元素替換成指定的HTML或DOM元素 $("<b>Paragraph. </b>").replaceAll("p"); //用匹配的元素替換掉所有 selector匹配到的元素刪除
$("p").empty(); //刪除匹配的元素集合中所有的子節(jié)點(diǎn),不包括本身 $("p").remove(); //刪除所有匹配的元素,包括本身六、事件
頁(yè)面載入
當(dāng)頁(yè)面載入成功后再運(yùn)行的函數(shù)事件
$(document).ready(function(){do something... });//簡(jiǎn)寫(xiě) $(function($) {do something... });頁(yè)面處理
//bind 為每個(gè)匹配元素綁定事件處理函數(shù),綁定多個(gè)用{}。 $("p").bind("click", function(){alert( $(this).text() ); }); $(menuF).bind({"mouseover":function () {$(menuS).parent().removeClass("hide");},"mouseout":function () {$(menuS).parent().addClass("hide"); } }); $("p").one( "click", fun...) //one 綁定一個(gè)一次性的事件處理函數(shù) $("p").unbind( "click" ) //解綁一個(gè)事件頁(yè)面委派
// 與bind 不同的是當(dāng)時(shí)間發(fā)生時(shí)才去臨時(shí)綁定。 $("p").delegate("click",function(){do something... });$("p").undelegate(); //p元素刪除由 delegate() 方法添加的所有事件 $("p").undelegate("click") //從p元素刪除由 delegate() 方法添加的所有click事件事件
$("p").click(); //單擊事件 $("p").dblclick(); //雙擊事件 $("input[type=text]").focus() //元素獲得焦點(diǎn)時(shí),觸發(fā) focus 事件 $("input[type=text]").blur() //元素失去焦點(diǎn)時(shí),觸發(fā) blur事件 $("button").mousedown()//當(dāng)按下鼠標(biāo)時(shí)觸發(fā)事件 $("button").mouseup() //元素上放松鼠標(biāo)按鈕時(shí)觸發(fā)事件 $("p").mousemove() //當(dāng)鼠標(biāo)指針在指定的元素中移動(dòng)時(shí)觸發(fā)事件 $("p").mouseover() //當(dāng)鼠標(biāo)指針位于元素上方時(shí)觸發(fā)事件 $("p").mouseout() //當(dāng)鼠標(biāo)指針從元素上移開(kāi)時(shí)觸發(fā)事件 $(window).keydown() //當(dāng)鍵盤(pán)或按鈕被按下時(shí)觸發(fā)事件 $(window).keypress() //當(dāng)鍵盤(pán)或按鈕被按下時(shí)觸發(fā)事件,每輸入一個(gè)字符都觸發(fā)一次 $("input").keyup() //當(dāng)按鈕被松開(kāi)時(shí)觸發(fā)事件 $(window).scroll() //當(dāng)用戶滾動(dòng)時(shí)觸發(fā)事件 $(window).resize() //當(dāng)調(diào)整瀏覽器窗口的大小時(shí)觸發(fā)事件 $("input[type='text']").change() //當(dāng)元素的值發(fā)生改變時(shí)觸發(fā)事件 $("input").select() //當(dāng)input 元素中的文本被選擇時(shí)觸發(fā)事件 $("form").submit() //當(dāng)提交表單時(shí)觸發(fā)事件 $(window).unload() //用戶離開(kāi)頁(yè)面時(shí)七、效果
?基本
$("p").show() //顯示隱藏的匹配元素 $("p").show("slow"); //參數(shù)表示速度,("slow","normal","fast"),也可為900毫秒 $("p").hide() //隱藏顯示的元素 $("p").toggle(); //切換 顯示/隱藏滑動(dòng)
$("p").slideDown("900"); //用900毫秒時(shí)間將段落滑下 $("p").slideUp("900"); //用900毫秒時(shí)間將段落滑上 $("p").slideToggle("900"); //用900毫秒時(shí)間將段落滑上,滑下淡入淡出
$("p").fadeIn("900"); //用900毫秒時(shí)間將段落淡入 $("p").fadeOut("900"); //用900毫秒時(shí)間將段落淡出 $("p").fadeToggle("900"); //用900毫秒時(shí)間將段落淡入,淡出 $("p").fadeTo("slow", 0.6); //用900毫秒時(shí)間將段落的透明度調(diào)整到0.6八、對(duì)象訪問(wèn)
$.trim() //去除字符串兩端的空格 $.each() //遍歷一個(gè)數(shù)組或?qū)ο?#xff0c;for循環(huán) $.inArray() //返回一個(gè)值在數(shù)組中的索引位置,不存在返回-1 $.grep() //返回?cái)?shù)組中符合某種標(biāo)準(zhǔn)的元素 $.extend() //將多個(gè)對(duì)象,合并到第一個(gè)對(duì)象 $.makeArray() //將對(duì)象轉(zhuǎn)化為數(shù)組 $.type() //判斷對(duì)象的類別(函數(shù)對(duì)象、日期對(duì)象、數(shù)組對(duì)象、正則對(duì)象等等 $.isArray() //判斷某個(gè)參數(shù)是否為數(shù)組 $.isEmptyObject() //判斷某個(gè)對(duì)象是否為空(不含有任何屬性) $.isFunction() //判斷某個(gè)參數(shù)是否為函數(shù) $.isPlainObject() //判斷某個(gè)參數(shù)是否為用"{}"或"new Object"建立的對(duì)象 $.support() //判斷瀏覽器是否支持某個(gè)特性十、實(shí)例
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title><style>.divH {height: 1800px;}.divT {width: 50px;height: 50px;font-size: 23px;background-color: #2F4F4F;color: white;position: fixed;right: 18px;bottom: 18px;}.divT:hover{cursor: pointer;}.hide {display: none;}</style> </head> <body><div class="divH"></div><div class="divT hide" οnclick="ReturnTop();"><strong>返回頂部</strong></div><script src="../../jquery-1.12.4.js"></script><script>window.onscroll = function () {var current = $(window).scrollTop();if (current > 180){$(".divT").removeClass("hide");}else {$(".divT").addClass("hide");}};function ReturnTop() {$(window).scrollTop(0);}</script> </body> </html> 返回頂部 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title><style>.menu{height: 600px;width: 30%;background-color: #2F4F4F;float: left;}.title{line-height: 50px;color: #ddd;}.title:hover{cursor: pointer;color: lightcyan;font-size: 18px;}.hide{display: none;}</style> </head><body><div class="outer"><div class="menu"><div class="item"><div class="title" οnclick="Show(this);">菜單一</div><div class="con"><div>111</div><div>111</div><div>111</div></div></div><div class="item"><div class="title" οnclick="Show(this);">菜單二</div><div class="con hide"><div>222</div><div>222</div><div>222</div></div></div><div class="item"><div class="title" οnclick="Show(this);">菜單三</div><div class="con hide"><div>333</div><div>333</div><div>333</div></div></div></div></div><script src="../../jquery-1.12.4.js"></script><script>function Show(self) {$(self).next().removeClass("hide").parent().siblings().children(".con").addClass("hide");}</script> </body> </html> 左側(cè)菜單 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title><style>*{margin: 0px;padding: 0px;}.tab_outer{margin: 0px auto;width: 60%;}.menu{background-color: #cccccc;border: 1px solid #ccc;line-height: 40px;}.menu li{display: inline-block;color: white;}.menu li:hover {cursor: pointer;}.menu a{padding: 11px;}.content{border: 1px solid #ccc;height: 300px;font-size: 30px;}.hide{display: none;}.current{background-color: #0099dd;color: black;}</style> </head> <body><div class="tab_outer"><ul class="menu"><li xxx="c1" class="current" οnclick="Tab(this);">菜單一</li><li xxx="c2" οnclick="Tab(this);">菜單二</li><li xxx="c3" οnclick="Tab(this);">菜單三</li></ul><div class="content"><div id="c1">內(nèi)容一</div><div id="c2" class="hide">內(nèi)容二</div><div id="c3" class="hide">內(nèi)容三</div></div></div><script src="../../jquery-1.12.4.js"></script><script>function Tab(self) {$(self).addClass("current").siblings().removeClass("current");var x = "#" + $(self).attr("xxx");$(x).removeClass("hide").siblings().addClass("hide");}</script> </body> </html> 菜單切換 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title> </head> <body><button id="in">fadein</button><button id="out">fadeout</button><button id="toggle">fadetoggle</button><button id="fadeto">fadeto</button><div id="id1" style="display:none; width: 80px;height: 80px;background-color: blueviolet"></div><div id="id2" style="display:none; width: 80px;height: 80px;background-color: orangered "></div><div id="id3" style="display:none; width: 80px;height: 80px;background-color: darkgreen "></div><script src="../../jquery-1.12.4.js"></script><script>$(document).ready(function(){$("#in").click(function(){$("#id1").fadeIn(1000);$("#id2").fadeIn(1000);$("#id3").fadeIn(1000);});$("#out").click(function(){$("#id1").fadeOut(1000);$("#id2").fadeOut(1000);$("#id3").fadeOut(1000);});$("#toggle").click(function(){$("#id1").fadeToggle(1000);$("#id2").fadeToggle(1000);$("#id3").fadeToggle(1000);});$("#fadeto").click(function(){$("#id1").fadeTo(1000,0.4);$("#id2").fadeTo(1000,0.5);$("#id3").fadeTo(1000,0);});});</script> </body> </html> 淡入淡出 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title><style>#flipshow,#content,#fliphide,#toggle{padding: 5px;text-align: center;background-color: blueviolet;border:solid 1px red;}#content{padding: 50px;display: none;}</style> </head> <body><div id="flipshow">出現(xiàn)</div><div id="fliphide">隱藏</div><div id="toggle">toggle</div><div id="content">helloworld</div><script src="../../jquery-1.12.4.js"></script><script>$(document).ready(function(){$("#flipshow").click(function(){$("#content").slideDown(1000);});$("#fliphide").click(function(){$("#content").slideUp(1000);});$("#toggle").click(function(){$("#content").slideToggle(1000);})});</script> </body> </html> 滑動(dòng) <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title> </head> <body><!--1 隱藏與顯示--><!--2 淡入淡出--><!--3 滑動(dòng)--><!--4 效果-回調(diào):每一個(gè)動(dòng)畫(huà)執(zhí)行完畢之后所能執(zhí)行的函數(shù)方法或者所能做的一件事--><p>hello</p><button id="hide">隱藏</button><button id="show">顯示</button><button id="toggle">隱藏/顯示</button><script src="../../jquery-1.12.4.js"></script><script>$(document).ready(function(){$("#hide").click(function(){$("p").hide(1000);});$("#show").click(function(){$("p").show(1000);});//用于切換被選元素的 hide() 與 show() 方法。$("#toggle").click(function(){$("p").toggle(2000);});});</script> </body> </html> 隱藏顯示 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title> </head> <body> <div class="outer"><div class="section"><div class="icons" style="display: inline-block"><a οnclick="Add(this);"><button>+</button></a></div><div class="inputs" style="display: inline-block"><input type="checkbox"><input type="text" value="IP"></div></div></div><script src="../../jquery-1.12.4.js"></script><script>function Add(self) {$(self).parentsUntil("outer").clone().find("a").html("<button>-</button>").attr("onclick","Remove(this);").end().eq(1).appendTo(".outer");}function Remove(self) {$(self).parentsUntil("outer").eq(1).remove();}</script> </body> </html> 添加和刪除標(biāo)簽 <!DOCTYPE html> <html lang="en"> <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width"><meta http-equiv="X-UA-Compatible" content="IE=8"><title>購(gòu)物商城</title><style>*{margin: 0;padding: 0;}.outer{position:relative;width:350px;height:350px;border:1px solid black;}.outer .small-box{position: relative;z-index: 1;}.outer .small-box .mark{position: absolute;display: block;width: 350px;height: 350px;background-color: #fff;filter: alpha(opacity=0);opacity: 0;z-index: 10;}.outer .small-box .float-box{display: none;width: 175px;height: 175px;position: absolute;background: #DAEEFC;filter: alpha(opacity=40);opacity: 0.4;}.outer .big-box{position: absolute;top: 0;left: 351px;width: 350px;height: 350px;overflow: hidden;border: 1px solid transparent;z-index: 1;}.outer .big-box img{position: absolute;z-index: 5}</style> </head> <body><div class="outer"><div class="small-box"><div class="mark"></div><div class="float-box" ></div><img width="350" height="350" src="../../css/1.jpg"></div><div class="big-box"><img width="900px" height="900px" src="../../css/1.jpg" ></div></div><script src="../../jquery-1.12.4.js"></script><script>$(function(){$(".mark").mouseover(function () {$(".float-box").css("display","block");$(".big-box").css("display","block");});$(".mark").mouseout(function () {$(".float-box").css("display","none");$(".big-box").css("display","none");});$(".mark").mousemove(function (e) {var _event = e || window.event; //兼容多個(gè)瀏覽器的event參數(shù)模式var float_box_width = $(".float-box")[0].offsetWidth;var float_box_height = $(".float-box")[0].offsetHeight;//175,175var float_box_width_half = float_box_width / 2;var float_box_height_half = float_box_height/ 2;//87.5,87.5var small_box_width = $(".outer")[0].offsetWidth;var small_box_height = $(".outer")[0].offsetHeight;//360,360var mouse_left = _event.clientX - float_box_width_half;var mouse_top = _event.clientY - float_box_height_half;if (mouse_left < 0) {mouse_left = 0;} else if (mouse_left > small_box_width - float_box_width) {mouse_left = small_box_width - float_box_width;}if (mouse_top < 0) {mouse_top = 0;} else if (mouse_top > small_box_height - float_box_height) {mouse_top = small_box_height - float_box_height;}$(".float-box").css("left",mouse_left + "px");$(".float-box").css("top",mouse_top + "px");var percentX = ($(".big-box img")[0].offsetWidth - $(".big-box")[0].offsetWidth) / (small_box_width - float_box_width);var percentY = ($(".big-box img")[0].offsetHeight - $(".big-box")[0].offsetHeight) / (small_box_height - float_box_height);console.log($(".big-box img")[0].offsetWidth,$(".big-box")[0].offsetWidth,small_box_width,float_box_width)console.log(percentX,percentY)$(".big-box img").css("left",-percentX * mouse_left + "px");$(".big-box img").css("top",-percentY * mouse_top + "px")})})</script> </body> </html> 商品放大鏡 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title><style>*{margin: 0;padding: 0;}.hide{display:none;}.header-nav {height: 39px;background: #c9033b;}.header-nav .bg{background: #c9033b;}.header-nav .nav-allgoods .menuEvent {display: block;height: 39px;line-height: 39px;text-decoration: none;color: #fff;text-align: center;font-weight: bold;font-family: 微軟雅黑;color: #fff;width: 100px;}.header-nav .nav-allgoods .menuEvent .catName {height: 39px;line-height: 39px;font-size: 15px;}.header-nav .nav-allmenu a {display: inline-block;height: 39px;vertical-align: top;padding: 0 15px;text-decoration: none;color: #fff;float: left;}.header-menu a{color:#656565;}.header-menu .menu-catagory{position: absolute;background-color: #fff;border-left:1px solid #fff;height: 316px;width: 230px;z-index: 4;float: left;}.header-menu .menu-catagory .catagory {border-left:4px solid #fff;height: 104px;border-bottom: solid 1px #eaeaea;}.header-menu .menu-catagory .catagory:hover {height: 102px;border-left:4px solid #c9033b;border-bottom: solid 1px #bcbcbc;border-top: solid 1px #bcbcbc;}.header-menu .menu-content .item{margin-left:230px;position:absolute;background-color:white;height:314px;width:500px;z-index:4;float:left;border: solid 1px #bcbcbc;border-left:0;box-shadow: 1px 1px 5px #999;}</style> </head> <body><div class="pg-header"><div class="header-nav"><div class="container narrow bg"><div class="nav-allgoods left"><a id="all_menu_catagory" href="#" class="menuEvent"><b class="catName">全部商品分類</b>><span class="arrow" style="display: inline-block;vertical-align: top;"></span></a></div></div></div><div class="header-menu"><div class="container narrow hide"><div id="nav_all_menu" class="menu-catagory"><div class="catagory" float-content="one"><div class="title">家電</div><div class="body"><a href="#">空調(diào)</a></div></div><div class="catagory" float-content="two"><div class="title">床上用品</div><div class="body"><a href="http://www.baidu.com">床單</a></div></div><div class="catagory" float-content="three"><div class="title">水果</div><div class="body"><a href="#">橘子</a></div></div></div><div id="nav_all_content" class="menu-content"><div class="item hide" float-id="one"><dl><dt><a href="#" class="red">廚房用品</a></dt><dd><span>|?<a href="#" target="_blank" title="勺子">勺子</a>?</span></dd></dl><dl><dt><a href="#" class="red">廚房用品</a></dt><dd><span>|?<a href="#" target="_blank" title="菜刀">菜刀</a>?</span></dd></dl><dl><dt><a href="#" class="red">廚房用品</a></dt><dd><span>|?<a href="#">菜板</a>?</span></dd></dl><dl><dt><a href="#" class="red">廚房用品</a></dt><dd><span>|?<a href="#" target="_blank" title="碗">碗</a>?</span></dd></dl></div><div class="item hide" float-id="two"><dl><dt><a href="#" class="red">床上用品</a></dt><dd><span>|?<a href="#" target="_blank" title="">枕頭</a>?</span></dd></dl><dl><dt><a href="#" class="red">床上用品</a></dt><dd><span>|?<a href="#" target="_blank" title="角閥">夏涼被</a>?</span></dd></dl><dl><dt><a href="#" class="red">床上用品</a></dt><dd><span>|?<a href="#" target="_blank" title="角閥">嘿嘿嘿</a>?</span></dd></dl></div><div class="item hide" float-id="three"><dl><dt><a href="#" class="red">廚房用品</a></dt><dd><span>|?<a href="#" target="_blank" title="角閥">微波爐</a>?</span></dd></dl><dl><dt><a href="#" class="red">廚房用品</a></dt><dd><span>|?<a href="http://www.meilele.com/category-jiaofa" target="_blank" title="角閥">金菜刀</a>?</span></dd></dl></div></div></div></div> </div><script src="../../jquery-1.12.4.js"></script> <script>$(function () {Change("#all_menu_catagory","#nav_all_menu","#nav_all_content")});function Change(menuF,menuS,menuT) {$(menuF).bind({"mouseover":function () {$(menuS).parent().removeClass("hide");},"mouseout":function () {$(menuS).parent().addClass("hide");}});$(menuS).children().bind({"mouseover":function () {$(menuS).parent().removeClass("hide");var $item = $(menuT).find('[float-id="' + $(this).attr("float-content") + '"]');$item.removeClass("hide").siblings().addClass("hide");},"mouseout":function () {$(menuS).parent().addClass("hide");$(menuT).parent().addClass("hide");}});$(menuT).children().bind({"mouseover":function () {$(menuS).parent().removeClass("hide");$(this).removeClass("hide");},"mouseout":function () {$(menuS).parent().addClass("hide");$(this).addClass("hide");}})} </script> </body> </html> 商品菜單?
轉(zhuǎn)載于:https://www.cnblogs.com/wu-chao/p/8260130.html
總結(jié)
- 上一篇: 温州商学院计算机二级office考试时间
- 下一篇: FFmpeg的下载及其简单使用