如何使用 jQuery 触发点击事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17270568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:43:24  来源:igfitidea点击:

How to trigger tap event with jQuery

javascriptjqueryjquery-mobiletouch

提问by Lukas

I need to set taptrigger on some selectors. I'm using jQuery Mobile and this function, so what is not right?

我需要tap在一些选择器上设置触发器。我正在使用 jQuery Mobile 和这个功能,有什么不对的?

window.onload = load;

function load() {
  $('.togglePlay').trigger('tap');
}

回答by suhailvs

try:

尝试:

$(document).ready(function(){
    $('.togglePlay').trigger('click');
});

回答by Penny Liu

Look into tapand tapholdtouch event.

查看点击点击触摸事件。

// The tap event won't be emitted along with the taphold event
$.event.special.tap.emitTapOnTaphold = false;

$("#fire").on("taphold", function() {
  $(this).addClass("colorize");
});
$("#banana").on("tap", function() {
  $(this).hide();
});
body {
  text-align: center;
}

span {
  font-size: 3rem;
}

span:hover {
  cursor: pointer;
}

.colorize {
  color: transparent;
  text-shadow: 0 0 0 red;
}
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

<h3>If you tap and hold me for 750 milliseconds, I will fill up with color.</h3>
<span id="fire"></span>
<hr />
<h3>If you tap me quick, I will dispear.</h3>
<span id="banana"></span>

回答by krishgopinath

Assuming the loading page has a div containing data-role=pageand its idis mypage, you could use the pageinitevent to fire up the clickon '.togglePlay'like this :

假设加载页面有一个包含 divdata-role=pageidis的 div mypage,您可以使用该pageinit事件来启动clickon ,'.togglePlay'如下所示:

$(document).on("pageinit", "#mypage", function () {
  $('.togglePlay').trigger('click');
});

References

参考

回答by malthouser

you should be able to set autoplay=true or some other setting with...

您应该能够设置 autoplay=true 或其他一些设置...

<video controls autoplay>
    <source src="movie.mp4" type="video/mp4">
    <source src="movie.ogg" type="video/ogg">
    Your browser does not support the video tag.
</video> 

example from: http://www.w3schools.com/tags/att_video_autoplay.asp

示例来自:http: //www.w3schools.com/tags/att_video_autoplay.asp

without the use of js

不使用js

回答by Suryavel TR

I use jQuery tap() method.

我使用 jQuery tap() 方法。

$('.togglePlay').tap();

http://api.jquerymobile.com/tap/

http://api.jquerymobile.com/tap/

This works for me :)

这对我有用:)