亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery中trigger()方法用法實例

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

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

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

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

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

參數(shù)列表:

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

實例代碼:

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

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://chabaoo.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>點擊激活事件</button>
</body>
</html>

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

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

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

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

參數(shù)列表:

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

實例代碼:

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

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://chabaoo.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>點擊激活事件</button>
</body>
</html>

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

相關(guān)文章

最新評論