jQuery事件綁定用法詳解
本文實例講述了jQuery事件綁定。分享給大家供大家參考,具體如下:
style.css
*{margin:0;padding:0;} body { font-size: 13px; line-height: 130%; padding: 60px } #panel { width: 300px; border: 1px solid #0050D0 } .head { padding: 5px; background: #96E555; cursor: pointer } .content { padding: 10px; text-indent: 2em; border-top: 1px solid #0050D0;display:block;display:none; }
demo1.html
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="css/style.css"> <script type="text/javascript" src="js/jquery-1.10.1.min.js"></script> <script type="text/javascript"> $(function(){ $("#panel h5.head").bind("click",function(){ $(this).next("div.content").show(); }) }) </script> </head> <body> <div id="panel"> <h5 class="head">什么是jQuery?</h5> <div class="content"> jQuery是繼Prototype之后又一個優(yōu)秀的JavaScript庫,它是一個由 John Resig 創(chuàng)建于2006年1月的開源項目。 jQuery憑借簡潔的語法和跨平臺的兼容性,極大地簡化了JavaScript開發(fā)人員遍歷HTML文檔、 操作DOM、處理事件、執(zhí)行動畫和開發(fā)Ajax。 它獨特而又優(yōu)雅的代碼風(fēng)格改變了JavaScript程序員的設(shè)計思路和編寫程序的方式。 </div> </div> </body> </html>
demo2.html
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="css/style.css"> <script type="text/javascript" src="js/jquery-1.10.1.min.js"></script> <script type="text/javascript"> $(function(){ $("#panel h5.head").bind("click",function(){ var $content = $(this).next("div.content"); if($content.is(":visible")){ $content.hide(); }else{ $content.show(); } }) }) </script> </head> <body> <div id="panel"> <h5 class="head">什么是jQuery?</h5> <div class="content"> jQuery是繼Prototype之后又一個優(yōu)秀的JavaScript庫,它是一個由 John Resig 創(chuàng)建于2006年1月的開源項目。 jQuery憑借簡潔的語法和跨平臺的兼容性,極大地簡化了JavaScript開發(fā)人員遍歷HTML文檔、 操作DOM、處理事件、執(zhí)行動畫和開發(fā)Ajax。 它獨特而又優(yōu)雅的代碼風(fēng)格改變了JavaScript程序員的設(shè)計思路和編寫程序的方式。 </div> </div> </body> </html>
demo3.html
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="css/style.css"> <script type="text/javascript" src="js/jquery-1.10.1.min.js"></script> <script type="text/javascript"> $(function(){ $("#panel h5.head").bind("mouseover",function(){ $(this).next("div.content").show(); }); $("#panel h5.head").bind("mouseout",function(){ $(this).next("div.content").hide(); }) }) </script> </head> <body> <div id="panel"> <h5 class="head">什么是jQuery?</h5> <div class="content"> jQuery是繼Prototype之后又一個優(yōu)秀的JavaScript庫,它是一個由 John Resig 創(chuàng)建于2006年1月的開源項目。 jQuery憑借簡潔的語法和跨平臺的兼容性,極大地簡化了JavaScript開發(fā)人員遍歷HTML文檔、 操作DOM、處理事件、執(zhí)行動畫和開發(fā)Ajax。 它獨特而又優(yōu)雅的代碼風(fēng)格改變了JavaScript程序員的設(shè)計思路和編寫程序的方式。 </div> </div> </body> </html>
demo4.html
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="css/style.css"> <script type="text/javascript" src="js/jquery-1.10.1.min.js"></script> <script type="text/javascript"> $(function(){ $("#panel h5.head").mouseover(function(){ $(this).next("div.content").show(); }); $("#panel h5.head").mouseout(function(){ $(this).next("div.content").hide(); }) }) </script> </head> <body> <div id="panel"> <h5 class="head">什么是jQuery?</h5> <div class="content"> jQuery是繼Prototype之后又一個優(yōu)秀的JavaScript庫,它是一個由 John Resig 創(chuàng)建于2006年1月的開源項目。 jQuery憑借簡潔的語法和跨平臺的兼容性,極大地簡化了JavaScript開發(fā)人員遍歷HTML文檔、 操作DOM、處理事件、執(zhí)行動畫和開發(fā)Ajax。 它獨特而又優(yōu)雅的代碼風(fēng)格改變了JavaScript程序員的設(shè)計思路和編寫程序的方式。 </div> </div> </body> </html>
效果圖如下:
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常見事件用法與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery擴展技巧總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
- jQuery?事件綁定及取消?bind?live?delegate?on?one區(qū)別解析
- jquery事件綁定方法介紹
- jQuery事件綁定和解綁、事件冒泡與阻止事件冒泡及彈出應(yīng)用示例
- jQuery實現(xiàn)的事件綁定功能基本示例
- jQuery的三種bind/One/Live/On事件綁定使用方法
- jQuery 全選 全不選 事件綁定的實現(xiàn)代碼
- jQuery事件綁定方法學(xué)習(xí)總結(jié)(推薦)
- jquery移除了live()、die(),新版事件綁定on()、off()的方法
- 關(guān)于Jquery中的事件綁定總結(jié)
- jquery事件綁定解綁機制源碼解析
- 深入理解jQuery事件綁定
- jQuery事件綁定on()與彈窗實現(xiàn)代碼
- jQuery事件綁定用法詳解(附bind和live的區(qū)別)
- jQuery實現(xiàn)按鈕只點擊一次后就取消點擊事件綁定的方法
- JQuery中DOM事件綁定用法詳解
- jQuery事件綁定on()、bind()與delegate() 方法詳解
- jQuery事件綁定與解除綁定實現(xiàn)方法
- jquery中click等事件綁定及移除的幾種方法小結(jié)
相關(guān)文章
jquery實現(xiàn)(textarea)placeholder自動換行
本文主要對jquery如何實現(xiàn)(textarea) placeholder自動換行的方法、思路進行介紹,下面就跟小編一起來看下吧2016-12-12Jquery+ajax請求data顯示在GridView上(asp.net)
Jquery ajax請求data顯示在asp.net中GridView控件上,需要的朋友可以參考下。2010-08-08Jquery組件easyUi實現(xiàn)手風(fēng)琴(折疊面板)示例
這篇文章主要為大家詳細介紹了Jquery組件easyUi實現(xiàn)手風(fēng)琴示例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08jQuery 圖片查看器插件 Viewer.js用法簡單示例
這篇文章主要介紹了jQuery 圖片查看器插件 Viewer.js用法,結(jié)合簡單示例形式分析了jQuery 圖片查看器插件 Viewer.js的基本功能、調(diào)用方法及后臺數(shù)據(jù)調(diào)用處理技巧,需要的朋友可以參考下2020-04-04jQuery EasyUI 右鍵菜單--關(guān)閉標簽/選項卡的簡單實例
下面小編就為大家?guī)硪黄猨Query EasyUI 右鍵菜單--關(guān)閉標簽/選項卡的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-10-10jQuery實現(xiàn)搜索頁面關(guān)鍵字的功能
這篇文章主要為大家詳細介紹了jQuery實現(xiàn)搜索頁面關(guān)鍵字的功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02從零開始學(xué)習(xí)jQuery (十) jQueryUI常用功能實戰(zhàn)
本文是實戰(zhàn)篇. 使用jQueryUI完成制作網(wǎng)站的大部分常用功能.2011-02-02