最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

.trigger()

.trigger( eventType, extraParameters ) 返回: jQuery

描述: 為給定的事件類型執(zhí)行所有處理器和行為附加到匹配的元素

  • version added: 1.0.trigger( eventType, extraParameters )

    eventType一個(gè)包含一個(gè)或多個(gè)JavaScript事件類型的字符串,比如click or submit。

    extraParameters個(gè)額外的參數(shù)數(shù)組傳遞給事件處理程序。

  • version added: 1.3.trigger( event )

    eventA jQuery.Event 對象.

Any event handlers attached with .bind() or one of its shortcut methods are triggered when the corresponding event occurs. They can be fired manually, however, with the .trigger() method. A call to .trigger() executes the handlers in the same order they would be if the event were triggered naturally by the user:

$('#foo').bind('click', function() {
      alert($(this).text());
    });
    $('#foo').trigger('click');

As of jQuery 1.3, .trigger()ed events bubble up the DOM tree; an event handler can stop the bubbling by returning false from the handler or calling the .stopPropagation() method on the event object passed into the event. Although .trigger() simulates an event activation, complete with a synthesized event object, it does not perfectly replicate a naturally-occurring event.

To trigger handlers bound via jQuery without also triggering the native event, use .triggerHandler() instead.

When we define a custom event type using the .bind() method, the second argument to .trigger() can become useful. For example, suppose we have bound a handler for the custom event to our element instead of the built-in click event as we did above:

$('#foo').bind('custom', function(event, param1, param2) {
  alert(param1 + "\n" + param2);
});
$('#foo').trigger('custom', ['Custom', 'Event']);

The event object is always passed as the first parameter to an event handler, but if additional parameters are specified during a .trigger() call as they are here, these parameters will be passed along to the handler as well.

Note the difference between the extra parameters we're passing here and the eventData parameter to the .bind() method. Both are mechanisms for passing information to an event handler, but the extraParameters argument to .trigger() allows information to be determined at the time the event is triggered, while the eventData argument to .bind() requires the information to be already computed at the time the handler is bound.

Examples:

Example: Clicks to button #2 also trigger a click for button #1.

<!DOCTYPE html>
<html>
<head>
  <style>

button { margin:10px; }
div { color:blue; font-weight:bold; }
span { color:red; }
</style>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
  <button>Button #1</button>
<button>Button #2</button>
<div><span>0</span> button #1 clicks.</div>

<div><span>0</span> button #2 clicks.</div>
<script>
$("button:first").click(function () {
update($("span:first"));
});
$("button:last").click(function () {
$("button:first").trigger('click');

update($("span:last"));
});

function update(j) {
var n = parseInt(j.text(), 10);
j.text(n + 1);
}
</script>

</body>
</html>

Demo:

Example: To submit the first form without using the submit() function, try:

$("form:first").trigger("submit")

Example: To submit the first form without using the submit() function, try:

var event = jQuery.Event("submit");
$("form:first").trigger(event);
if ( event.isDefaultPrevented() ) {
// Perform an action...
}

Example: To pass arbitrary data to an event:

$("p").click( function (event, a, b) {
// when a normal click fires, a and b are undefined
// for a trigger like below a refers to "foo" and b refers to "bar"

} ).trigger("click", ["foo", "bar"]);

Example: To pass arbitrary data through an event object:

var event = jQuery.Event("logged");
event.user = "foo";
event.pass = "bar";
$("body").trigger(event);

Example: Alternative way to pass data through an event object:

$("body").trigger({
type:"logged",
user:"foo",
pass:"bar"

});
jQuery 1.6 API 中文版腳本之家整理、修訂 (2011年6月)
长宁区| 赫章县| 灵寿县| 兴城市| 新安县| 杭州市| 连南| 宁河县| 乐山市| 潮州市| 千阳县| 盐城市| 郸城县| 杭锦旗| 孝昌县| 汝南县| 沙田区| 巴楚县| 台南市| 商丘市| 绍兴县| 石城县| 秀山| 肇源县| 绥宁县| 漯河市| 虞城县| 霍山县| 屯昌县| 石狮市| 新化县| 安龙县| 柳州市| 阿鲁科尔沁旗| 临汾市| 桂东县| 两当县| 宕昌县| 司法| 夹江县| 祥云县|