简体   繁体   English

如何使用 jQuery 触发点击事件

[英]How to trigger tap event with jQuery

I need to set tap trigger on some selectors.我需要在一些选择器上设置tap触发器。 I'm using jQuery Mobile and this function, so what is not right?我正在使用 jQuery Mobile 和这个功能,有什么不对的?

window.onload = load;

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

Look into tap and taphold touch 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>

try:尝试:

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

Assuming the loading page has a div containing data-role=page and its id is mypage , you could use the pageinit event to fire up the click on '.togglePlay' like this :假设加载页面有一个包含data-role=page的 div 并且它的idmypage ,你可以使用pageinit事件来触发对'.togglePlay'click ,如下所示:

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

References参考

I use jQuery tap() method.我使用 jQuery tap() 方法。

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

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

This works for me :)这对我有用:)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM