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

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

 更新時(shí)間:2015年01月19日 11:46:05   投稿:shichen2014  
這篇文章主要介紹了jQuery中trigger()方法用法,實(shí)例分析了trigger()方法的功能、定義及觸發(fā)匹配元素指定類(lèi)型事件的使用技巧,需要的朋友可以參考下

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

此方法觸發(fā)匹配元素指定類(lèi)型的事件。

語(yǔ)法結(jié)構(gòu)一:
規(guī)定匹配元素被觸發(fā)的事件類(lèi)型。

復(fù)制代碼 代碼如下:
$(selector).trigger(event,param1,param2,...)

參數(shù)列表:

參數(shù) 描述
event 規(guī)定指定元素要觸發(fā)的事件。
可以是自定義事件(使用 bind() 函數(shù)來(lái)附加),或者任何標(biāo)準(zhǔn)事件。
param 可選。傳遞到事件處理程序的額外參數(shù)。
額外的參數(shù)對(duì)自定義事件特別有用。

實(shí)例代碼:

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

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>trigger()函數(shù)-腳本之家</title>
<style type="text/css">
div{
  width:200px;
  height:200px;
  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").click(function(){
    $("div").append("添加的內(nèi)容");
  });
  $("button").click(function(){
    $("div").trigger("click");
  })
})
</script>
</head>
<body>
  <div></div>
  <button>點(diǎn)擊激活事件</button>
</body>
</html>

當(dāng)點(diǎn)擊button按鈕可以的時(shí)候可以出發(fā)div上的click事件,進(jìn)而執(zhí)行click事件處理函數(shù)。

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

以事件對(duì)象作為參數(shù)規(guī)定匹配元素要被觸發(fā)的事件類(lèi)型。

復(fù)制代碼 代碼如下:
$(selector).trigger(eventObj)

參數(shù)列表:

參數(shù) 描述
eventObj 事件對(duì)象規(guī)定了事件發(fā)生時(shí)運(yùn)行的函數(shù)。

實(shí)例代碼:

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

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.dbjr.com.cn/" />
<title>trigger()函數(shù)-腳本之家</title>
<style type="text/css">
div{
  width:200px;
  height:200px;
  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").click(function(){
    $("div").append("添加的內(nèi)容");
  });
  var e=jQuery.Event("click");
  $("button").click(function(){
    $("div").trigger(e);
  })
})
</script>
</head>
<body>
  <div></div>
  <button>點(diǎn)擊激活事件</button>
</body>
</html>

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

相關(guān)文章

最新評(píng)論