javascript元素.click()发布Safari

javascript element.click() issue Safari

本文关键字:发布 Safari 元素 click javascript      更新时间:2024-02-24

单击"subButton2"按钮后,将单击"uploadBtn"(显示:none;)。

根据这一点,它应该是跨浏览器的:

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_html_click

以下是我的代码,适用于chrome、opera和firefox,但在safari:中失败

var page = window.location.toString();
if(page.indexOf('register') !== -1){
    var subButton2 = document.getElementById("subButton2");
    subButton2.onclick = function () {
        var uploadBtn = document.getElementById("fileBtnHide");
        //THIS FAILS IN SAFARI IF uploadBtn style= display:none;
        uploadBtn.click();
    };
 };

***只有javascript,没有jquery解决方案,请

它正在运行:http://monkey-me.herokuapp.com/register

"照片"按钮是触发第二个按钮的按钮。

与其将其设置为不显示(safari可能会将其解释为禁用),不如使用其他一些css属性隐藏它。

#fileBtnHide {
    height: 0;
    width: 0;
    opacity: 0;
    position: absolute;
}