在Firefox如何实现链接的click() ?想要通过脚本点击一个链接。是像这样的情况:<a href="http://www.abc.com" id="abc">abc</a>document.getElementById("abc").click()在IE和opera中正常,在firefox不行.不要用document.location.href=url的方法来实现,还有其它方法吗?

解决方案 »

  1.   

    a那个元素不可以。。
    你还是换方法吧。。按钮可以。。<input id="abc" type="button" onclick="alert('wc')" />
    <script type="text/javascript">
    var $ = function (id) {
    return document.getElementById(id);
    };a = $("abc");
    if (!document.createEvent) {
    a.click();
    } else {
    var o = a.ownerDocument.createEvent("MouseEvents");
    o.initEvent("click", false, true);
    a.dispatchEvent(o);
    }
    </script>
      

  2.   

    firefox下你死心吧,下边是官网看到的...模模糊糊的还是看到了 tag
    ---------------------------------------------------------------------
        Gecko DOM Reference Summary The click method simulates a click on an element. Syntax element.click() Notes The click method is intended to be used with INPUT elements of type button, checkbox, radio, reset or submit. Gecko does not implement the click method on other elements that might be expected to respond to mouse–clicks such as links (A elements), nor will it necessarily fire the click event of other elements. Non–Gecko DOMs may behave differently. When a click is used with elements that support it (e.g. one of the INPUT types listed above), it also fires the element's click event which will bubble up to elements higher up the document tree (or event chain) and fire their click events too. However, bubbling of a click event will not cause an A element to initiate navigation as if a real mouse-click had been received. Specification click 
    ---------------------------------------------------------------------------