【问题标题】:how to invoke click event from javascript?如何从javascript调用点击事件?
【发布时间】:2011-01-23 17:02:28
【问题描述】:

下面是我的asp(HTML)代码

<a id="More_Info" onclick ="window.top.location.href ='More_Info.asp?ussl=H&Start=<%=nRecCount%>&RS=<%=RecordStart%>;'" href="#">

我想通过我的 javascript 激活 onclick ="window.top.location.href ='More_Info.asp?ussl=H&amp;Start=&lt;%=nRecCount%&gt;&amp;RS=&lt;%=RecordStart%&gt;;'" onclick 事件...

<script type="text/javascript" >
{
//here i wand to activate the click event 
document.getElementById("More_Info").onclick // Something  like this
}
</script>

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    这是我为similar question 编写的函数的简化版本。您可以在Mozilla Developer Center documentation 中找到initMouseEvent 的参数列表,但您不需要更改任何内容。

    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");
        }
    }
    

    【讨论】:

    • 这是正确答案,接受的答案应该改为这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 2013-08-20
    • 1970-01-01
    • 2016-09-15
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多