国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

淺談jQuery的bind和unbind事件(綁定和解綁事件)

2024-05-06 15:10:27
字體:
供稿:網(wǎng)友

綁定其實(shí)就是把一些常規(guī)時(shí)間綁定到頁面,然后進(jìn)行各種常規(guī)操作

解綁就是接觸綁定,綁定的事件失效

要注意,iQuery中的  .事件  如(.click())其實(shí)就是單個(gè)的綁定事件的簡寫(bind("click"))

html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>02_事件綁定.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8">	<script language="JavaScript" src="../js/jquery-1.4.2.js"></script>	<link rel="stylesheet" type="text/css" href="./css/style.css" rel="external nofollow" /> </head> <body> 	 <div id="panel">			<input type="button" id="start" value="綁定事件">			<input type="button" id="stop" value="解綁事件">			<h5 class="head">什么是jQuery?</h5>			<div class="content">	jQuery是繼Prototype之后又一個(gè)優(yōu)秀的JavaScript庫,它是一個(gè)由 John Resig 創(chuàng)建于2006年1月的開源項(xiàng)目。jQuery憑借簡潔的語法和跨平臺的兼容性,極大地簡化了JavaScript開發(fā)人員遍歷HTML文檔、操作DOM、處理事件、執(zhí)行動(dòng)畫和開發(fā)Ajax。它獨(dú)特而又優(yōu)雅的代碼風(fēng)格改變了JavaScript程序員的設(shè)計(jì)思路和編寫程序的方式。			</div>		</div> </body> <script language="JavaScript"> //當(dāng)鼠標(biāo)單次點(diǎn)擊h5標(biāo)題時(shí),顯示答案;當(dāng)鼠標(biāo)雙次點(diǎn)擊h5標(biāo)題時(shí),隱藏答案//	$("h5").click(function(){//		if($("div[class=content]").is(":hidden")){//			$("div[class=content]").show();//		}else{//			$("div[class=content]").hide();//		}//	})	//	//動(dòng)態(tài)效果//	$("#start").click(function(){//		/*//		 * 動(dòng)態(tài)綁定點(diǎn)擊事件:綁定單個(gè)事件//		 * 	bind(type,data,fn)//		 * 		* type:指定要綁定的事件名稱//		 * 		* data:(可選)作為event.data屬性值傳遞給事件對象的額外數(shù)據(jù)對象//		 * 		* fn:回調(diào)函數(shù),function(){}//		 *///		$("h5").bind("click",function(){//			if($("div[class=content]").is(":hidden")){//				$("div[class=content]").show();//			}else{//				$("div[class=content]").hide();//			}//		});//		//	});//	$("#stop").click(function(){//		/*//		 * 動(dòng)態(tài)解綁定點(diǎn)擊事件//		 * 	unbind(type,fn)//		 * 		* type:(可選)指定要解綁的事件名稱//		 * 		* fn:(可選)回調(diào)函數(shù)//		 *///		$("h5").unbind();//	});	//	$("h5").mouseover(function(){//		$("div[class=content]").show();//	}).mouseout(function(){//		$("div[class=content]").hide();//	});		//動(dòng)態(tài)效果	$("#start").click(function(){		/*		 * 綁定事件:綁定多個(gè)事件		 * 	* 事件名稱之間,用空格隔開		 */		$("h5").bind("mouseover mouseout",function(){			if($("div[class=content]").is(":hidden")){				$("div[class=content]").show();			}else{				$("div[class=content]").hide();			}		});	});	$("#stop").click(function(){		/*		 * unbind(type)		 * 	* 默認(rèn)為空時(shí):解綁定所有事件		 * 	* 指定單個(gè)事件:解綁指定的單個(gè)事件		 * 	* 指定多個(gè)事件:解綁指定的多個(gè)事件		 */		$("h5").unbind("mouseover mouseout");			});	 </script></html>            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 丰顺县| 沙湾县| 班玛县| 石台县| 忻城县| 靖边县| 临猗县| 鲁山县| 搜索| 张家口市| 凤冈县| 同仁县| 镇平县| 高要市| 宁南县| 华宁县| 武强县| 靖西县| 勐海县| 永州市| 华亭县| 略阳县| 鄂州市| 通渭县| 丹东市| 西盟| 汾阳市| 启东市| 钟山县| 登封市| 麻城市| 湖南省| 武邑县| 鹤山市| 桐城市| 柳州市| 福贡县| 荥经县| 柳州市| 出国| 贡山|