如何从JavaScript调用点击事件? [英] how to invoke click event from javascript?
本文介绍了如何从JavaScript调用点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的asp(HTML)代码
Below is my asp(HTML) code
<a id="More_Info" onclick ="window.top.location.href ='More_Info.asp?ussl=H&Start=<%=nRecCount%>&RS=<%=RecordStart%>;'" href="#">
从我的javascript i wand中激活 onclick =window.top。 location.href ='More_Info.asp?ussl = H& Start =<%= nRecCount%>& RS =<%= RecordStart%> ;;'
onclick event ...
from my javascript i wand to activate the onclick ="window.top.location.href ='More_Info.asp?ussl=H&Start=<%=nRecCount%>&RS=<%=RecordStart%>;'"
onclick event...
<script type="text/javascript" >
{
//here i wand to activate the click event
document.getElementById("More_Info").onclick // Something like this
}
</script>
推荐答案
这是我为类似的问题。您可以在 initMouseEvent 的参数列表rel = nofollow noreferrer> Mozilla开发人员中心文档,但不需要更改任何内容。
This is a simplified version of a function I wrote for a similar question. You can find a list of the arguments to initMouseEvent
in the Mozilla Developer Center documentation but you shouldn't need to change anything.
function clickLink(link) {
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);
link.dispatchEvent(event);
}
else if (link.fireEvent) {
link.fireEvent("onclick");
}
}
这篇关于如何从JavaScript调用点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文