Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript模拟鼠标点击_Javascript_Html_Click_Mouseevent - Fatal编程技术网

如何使用javascript模拟鼠标点击

如何使用javascript模拟鼠标点击,javascript,html,click,mouseevent,Javascript,Html,Click,Mouseevent,我花了两天时间在谷歌上搜索,以找到一个跨浏览器的解决方案来模拟鼠标点击html,但还没有找到一个 //-- REGARDING javascript's fireEvent (for IE browsers) var lvs_event = 'click' ; var lvo_event = document.createEventObject(); argo_target.fireEvent( 'on' + lvs_event , lvo_

我花了两天时间在谷歌上搜索,以找到一个跨浏览器的解决方案来模拟鼠标点击html,但还没有找到一个

//-- REGARDING javascript's fireEvent (for IE browsers)
var lvs_event = 'click' ;              
var lvo_event = document.createEventObject();             
argo_target.fireEvent( 'on' + lvs_event , lvo_event );
//-------- does not work on either my winXP IE6 or my winVista IE8


//-- REGARDING javascript's dispatchEvent (for non-IE browsers)
var lvo_event = argo_target.ownerDocument.createEvent('MouseEvents') ;
lvo_event.initMouseEvent( 'click' , ... ) ;
argo_target.dispatchEvent( lvo_event ) ;
//-------- does not work on winVista FF3.6

//-- REGARDING inserting location.href
<a href    = '...'
   target  = '...'
   onclick = '...;location.href = this.href;...'
>
<script>
my_a.onclick();
<\/script>
//-------- works consistently BUT literally calls the onclick handler, ignoring all other <_a_> properties such as href and target

//-- REGARDING various jQuery solutions
$('#my_a').trigger('click');
//OR
$('#my_a').click();
//-------- does not work on any browsers (jQuery IS successfully being used for other features however)
/--关于javascript的fireEvent(适用于IE浏览器)
var lvs_事件='点击';
var lvo_event=document.createEventObject();
argo_target.firevent('on'+lvs_事件,lvo_事件);
//--------在我的winXP IE6或winVista IE8上都不工作
//--关于javascript的dispatchEvent(对于非IE浏览器)
var lvo_event=argo_target.ownerDocument.createEvent('MouseEvents');
lvo_event.initMouseEvent('click',…);
argo_目标调度事件(lvo_事件);
//--------不适用于winVista FF3.6
//--关于插入位置。href
我的_a.onclick();
//--------工作一致,但实际上调用onclick处理程序,忽略所有其他属性,如href和target
//--关于各种jQuery解决方案
$('my'u a')。触发器('click');
//或
$('my#u a')。单击();
//--------无法在任何浏览器上运行(但是jQuery已成功用于其他功能)
我的目标是:让一个flash按钮鼠标向下传递消息到js,这反过来会自动执行一个点击过程

当然,我可以让flash调用js,从js获取必要的html信息并将其返回给flash,然后flash可以执行as3 geturl,但我更愿意与现有的html环境过程相结合


我目前正在使用各种版本的ff、ie、opera、safari(用于win)、winXP和winVista上的chrome进行测试。

如果您想在触发时跟踪url,则必须在函数中这样说:

html:

<a id="link" href="http://google.com">Link</a>
<a id="trigger" href="#">Trigger link</a>  
$('#link').click(function(){ alert('hey'); });
$('#trigger').click(function(){
    var $link = $('#link');
    $link.trigger('click');
    // window.location.href = $link.attr('href');
    window.open($link.attr('href'), '_blank'); // Popup blockers might block this
});

你可以看看这个解决方案:它应该在IE中正常工作。如果没有,你使用的是什么版本的jquery?你所说的模拟点击是什么意思?@elclanrs字面意思是当用户点击某个特定的。。。如果该特定对象的onclick处理程序绑定了各种行为,那么应该调用这些行为。同样,如果该特定目标为“空白”,则应遵守该目标。但不仅仅是调用onclick指定的handlerOh,然后调用
$('my#u a')。trigger('click')
应该可以工作,不知道为什么不能工作…如果链接中的解决方案不能工作,我会尝试使用jquery.elclars的更新版本,谢谢您的回复。但是,这并不是真正模拟流程,而是查询的各种功能,从而模拟这些单独的功能。这可能会起作用,但在我的例子中,它忽略了“target=”blank“要求。还应该注意,根据我的测试,这个解决方案可以通过纯javascript实现浏览器安全:
my_a_标记.onclick()
以及
location.href=my_a_标记.href
lazy?在我测试了你的解决方案并确定了它的用途之后,我解释了为什么你的解决方案不是解决方案。。。哪一部分是懒惰的?另外,您的解决方案会忽略目标属性。。。查看我的原始帖子。我用目标属性更新了它!我的意思是谷歌搜索很简单。埃尔克兰斯,你又错了。。。window.open是弹出窗口阻止程序的基本触发器。。。自2002年以来,web开发人员一直在避免使用它。