jQuery事件綁定用法詳解
本文實(shí)例講述了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之后又一個(gè)優(yōu)秀的JavaScript庫,它是一個(gè)由 John Resig 創(chuàng)建于2006年1月的開源項(xiàng)目。
jQuery憑借簡(jiǎn)潔的語法和跨平臺(tái)的兼容性,極大地簡(jiǎn)化了JavaScript開發(fā)人員遍歷HTML文檔、
操作DOM、處理事件、執(zhí)行動(dòng)畫和開發(fā)Ajax。
它獨(dú)特而又優(yōu)雅的代碼風(fēng)格改變了JavaScript程序員的設(shè)計(jì)思路和編寫程序的方式。
</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之后又一個(gè)優(yōu)秀的JavaScript庫,它是一個(gè)由 John Resig 創(chuàng)建于2006年1月的開源項(xiàng)目。
jQuery憑借簡(jiǎn)潔的語法和跨平臺(tái)的兼容性,極大地簡(jiǎn)化了JavaScript開發(fā)人員遍歷HTML文檔、
操作DOM、處理事件、執(zhí)行動(dòng)畫和開發(fā)Ajax。
它獨(dú)特而又優(yōu)雅的代碼風(fēng)格改變了JavaScript程序員的設(shè)計(jì)思路和編寫程序的方式。
</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之后又一個(gè)優(yōu)秀的JavaScript庫,它是一個(gè)由 John Resig 創(chuàng)建于2006年1月的開源項(xiàng)目。
jQuery憑借簡(jiǎn)潔的語法和跨平臺(tái)的兼容性,極大地簡(jiǎn)化了JavaScript開發(fā)人員遍歷HTML文檔、
操作DOM、處理事件、執(zhí)行動(dòng)畫和開發(fā)Ajax。
它獨(dú)特而又優(yōu)雅的代碼風(fēng)格改變了JavaScript程序員的設(shè)計(jì)思路和編寫程序的方式。
</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之后又一個(gè)優(yōu)秀的JavaScript庫,它是一個(gè)由 John Resig 創(chuàng)建于2006年1月的開源項(xiàng)目。
jQuery憑借簡(jiǎn)潔的語法和跨平臺(tái)的兼容性,極大地簡(jiǎn)化了JavaScript開發(fā)人員遍歷HTML文檔、
操作DOM、處理事件、執(zhí)行動(dòng)畫和開發(fā)Ajax。
它獨(dú)特而又優(yōu)雅的代碼風(fēng)格改變了JavaScript程序員的設(shè)計(jì)思路和編寫程序的方式。
</div>
</div>
</body>
</html>
效果圖如下:

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常見事件用法與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery?事件綁定及取消?bind?live?delegate?on?one區(qū)別解析
- jquery事件綁定方法介紹
- jQuery事件綁定和解綁、事件冒泡與阻止事件冒泡及彈出應(yīng)用示例
- jQuery實(shí)現(xiàn)的事件綁定功能基本示例
- jQuery的三種bind/One/Live/On事件綁定使用方法
- jQuery 全選 全不選 事件綁定的實(shí)現(xiàn)代碼
- jQuery事件綁定方法學(xué)習(xí)總結(jié)(推薦)
- jquery移除了live()、die(),新版事件綁定on()、off()的方法
- 關(guān)于Jquery中的事件綁定總結(jié)
- jquery事件綁定解綁機(jī)制源碼解析
- 深入理解jQuery事件綁定
- jQuery事件綁定on()與彈窗實(shí)現(xiàn)代碼
- jQuery事件綁定用法詳解(附bind和live的區(qū)別)
- jQuery實(shí)現(xiàn)按鈕只點(diǎn)擊一次后就取消點(diǎn)擊事件綁定的方法
- JQuery中DOM事件綁定用法詳解
- jQuery事件綁定on()、bind()與delegate() 方法詳解
- jQuery事件綁定與解除綁定實(shí)現(xiàn)方法
- jquery中click等事件綁定及移除的幾種方法小結(jié)
相關(guān)文章
jquery實(shí)現(xiàn)(textarea)placeholder自動(dòng)換行
本文主要對(duì)jquery如何實(shí)現(xiàn)(textarea) placeholder自動(dòng)換行的方法、思路進(jìn)行介紹,下面就跟小編一起來看下吧2016-12-12
jQuery Validate驗(yàn)證框架詳解(推薦)
jQuery Validate 插件為表單提供了強(qiáng)大的驗(yàn)證功能,讓客戶端表單驗(yàn)證變得更簡(jiǎn)單,同時(shí)提供了大量的定制選項(xiàng),滿足應(yīng)用程序各種需求。有興趣的可以了解一下。2016-12-12
Jquery+ajax請(qǐng)求data顯示在GridView上(asp.net)
Jquery ajax請(qǐng)求data顯示在asp.net中GridView控件上,需要的朋友可以參考下。2010-08-08
Jquery Validate 正則表達(dá)式實(shí)用驗(yàn)證代碼大全
jQuery.validate 的正則驗(yàn)證功能,包括手機(jī)號(hào)碼、電話號(hào)碼、郵政編碼、QQ號(hào)碼、IP地址、字母和數(shù)字、中文的驗(yàn)證等2013-08-08
Jquery組件easyUi實(shí)現(xiàn)手風(fēng)琴(折疊面板)示例
這篇文章主要為大家詳細(xì)介紹了Jquery組件easyUi實(shí)現(xiàn)手風(fēng)琴示例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08
jQuery 圖片查看器插件 Viewer.js用法簡(jiǎn)單示例
這篇文章主要介紹了jQuery 圖片查看器插件 Viewer.js用法,結(jié)合簡(jiǎn)單示例形式分析了jQuery 圖片查看器插件 Viewer.js的基本功能、調(diào)用方法及后臺(tái)數(shù)據(jù)調(diào)用處理技巧,需要的朋友可以參考下2020-04-04
jQuery EasyUI 右鍵菜單--關(guān)閉標(biāo)簽/選項(xiàng)卡的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)硪黄猨Query EasyUI 右鍵菜單--關(guān)閉標(biāo)簽/選項(xiàng)卡的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-10-10
jQuery實(shí)現(xiàn)搜索頁面關(guān)鍵字的功能
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)搜索頁面關(guān)鍵字的功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
從零開始學(xué)習(xí)jQuery (十) jQueryUI常用功能實(shí)戰(zhàn)
本文是實(shí)戰(zhàn)篇. 使用jQueryUI完成制作網(wǎng)站的大部分常用功能.2011-02-02

