。点击()和实际点击一个按钮之间的区别? (使用Javascript / jQuery的) [英] Difference between .click() and actually clicking a button? (javascript/jQuery)
问题描述
我想弄清楚我一直有这个奇怪的问题,根本原因是现场点击触发。点击()之间的区别
I'm trying to figure out this weird issue I've been having, and the root cause is the difference between a live click and triggering .click()
.
我不会进入细节问题,但基本上当你点击输入按钮,它工作正常(有一个的onclick
事件)。但是,如果我叫。点击()
从别的地方(而不是实际单击该按钮)它不能正常工作。
I won't get into the details of the problem, but basically when you click on the input button it works fine (has an onclick
event). But if I call .click()
from somewhere else (instead of physically clicking the button) it doesn't work properly.
我的问题是 - ?有没有办法真正复制一个按钮的实际点击
My question is - is there a way to truly replicate an actual click on a button?
的 修改的
EDIT
问题:我打开加载内嵌PDF一个新窗口(aspx页面)。 如果我实际上点击链接,打开窗口罚款和PDF负荷。如果我使用。点击()
窗口打开时,我提示下载的PDF文件。我已经通过ADOBE READER设置,浏览器设置,以及有关提示注册表设置 - 据我所知,这些都可以因素对大画面,但现在我很担心,为什么鼠标点击。点击()之间的行为都在做不同的事情在所有
The problem: I'm opening a new window (aspx page) that loads an inline PDF. If I actually click on the link, the window opens fine and the PDF loads. If I use .click()
the window opens and I'm prompted to download the PDF file. I've been through Adobe Reader settings, browser settings, and registry settings about the prompting - I understand that these can be factors to the big picture, but right now I'm concerned about why the behavior between a mouse click and .click() are doing anything different at all.
推荐答案
我用这个功能来真正模仿鼠标点击:
I use this function to truly mimic a mouse click:
function clickLink(link) {
var cancelled = false;
if (document.createEvent) {
var event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0,
false, false, false, false,
0, null);
cancelled = !link.dispatchEvent(event);
}
else if (link.fireEvent) {
cancelled = !link.fireEvent("onclick");
}
}
这篇关于。点击()和实际点击一个按钮之间的区别? (使用Javascript / jQuery的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!