Jquery模拟点击< div role = button> [英] Jquery simulate a click on <div role = button>

查看:54
本文介绍了Jquery模拟点击< div role = button>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用jquery模拟按钮上的点击。

I need to simulate a click on a button using jquery.

常规Javascript MouseEvents(mousedown和mouseup)可以正常工作,但我想要jquery。

Regular Javascript MouseEvents (mousedown and mouseup) do work, but I want jquery.

我在jquery对象中有div :(只是一个引用)

I have the div in a jquery object: (just a reference)

它定义为

var $button = $(document.getElementById("iframe")...);

$ button - > < div id =1class =2role =button>< b>行动< / b>< / div>

我试过 $ button.click() $ button.trigger('click')但两者都不起作用。

I've tried with $button.click() and $button.trigger('click') but both don't work.

我读过 this ,但没有回答这个问题。

I've read this, but provides no answer to this question.

推荐答案

试试这个:

var e = document.createEvent("MouseEvents");
e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
$button[0].dispatchEvent(e);

这篇关于Jquery模拟点击&lt; div role = button&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆