如何从javascript调用click事件?

时间:2010-03-04 14:23:07

标签: javascript html

下面是我的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&Start=<%=nRecCount%>&RS=<%=RecordStart%>;'" onclick事件...

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

1 个答案:

答案 0 :(得分:8)

这是我为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");
    }
}