欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery中bind()方法用法實(shí)例

 更新時(shí)間:2015年01月19日 11:31:51   投稿:shichen2014  
這篇文章主要介紹了jQuery中bind()方法用法,實(shí)例分析了bind()方法的功能、定義及為匹配元素的特定事件綁定事件處理方法的技巧,需要的朋友可以參考下

本文實(shí)例講述了jQuery中bind()方法用法。分享給大家供大家參考。具體分析如下:

此方法為匹配元素的特定事件綁定事件處理方法。
在語(yǔ)法上bind()方法和one()方法是一樣的,它們的不同在于綁定的處理方法的執(zhí)行次數(shù)。

語(yǔ)法結(jié)構(gòu)一:

復(fù)制代碼 代碼如下:
$(selector).bind(type,data,function)

參數(shù)列表:
參數(shù) 描述
type 定義綁定到匹配元素中的事件類型。
如果有多個(gè)事件使用空格分隔。
data 可選。傳遞給事件對(duì)象的額外數(shù)據(jù)對(duì)象。
function 定義當(dāng)事件發(fā)生時(shí)運(yùn)行的方法。

實(shí)例代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>bind()函數(shù)-腳本之家</title>
<style type="text/css">
div{
  width:100px;
  height:100px;
  border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("div").bind("click",function(){$("div").css({color:"green",fontSize:"20px"})});
})
</script>
</head>
<body>
  <div>腳本之家歡迎您</div>
</body>
</html>

語(yǔ)法結(jié)構(gòu)二:

復(fù)制代碼 代碼如下:
$(selector).bind({type:function, type:function, ...})

參數(shù)列表:

參數(shù) 描述
{type:function, type:function, ...}         定義綁定到匹配元素的事件和事件處理方法。
type與function參數(shù)描述如上表。

實(shí)例代碼:

復(fù)制代碼 代碼如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>bind()函數(shù)-腳本之家</title>
<style type="text/css">
div{
  width:100px;
  height:100px;
  border:1px solid red
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("div").bind({click:function(){$("div").css("color","green")},
    mouseover:function(){$("div").css("background-color","blue")},
    dblclick:function(){$("div").css("background-color","red")}
  })
})
</script>
</head>
<body>
  <div>腳本之家歡迎您</div>
</body>
</html>

希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。

本文轉(zhuǎn)自:螞蟻部落http://www.softwhy.com/

相關(guān)文章

最新評(píng)論