简体   繁体   English

启用禁用按钮并使用Javascript单击它

[英]Enable a disabled button and click it with Javascript

I have a disabled button I want to click with Javascript. 我有一个禁用按钮,我想用Javascript点击。 The following function works in Chrome but not in Firefox. 以下功能适用于Chrome,但不适用于Firefox。
The problem with Firefox: Firefox javascript is too slow. Firefox的问题:Firefox javascript太慢了。
The button is still disabled if the code wants to click it. 如果代码想要单击它,该按钮仍然处于禁用状态。 How to click the button when it is enabled? 如何在启用时单击按钮?

function enable_and_click() {
    document.getElementById('button1').disabled=false;
    document.getElementById('button1').click();
}

Try the following: 请尝试以下方法:

document.getElementById('button1').removeAttribute('disabled');
document.getElementById('button1').click();

Update 更新

Using jQuery, a cross browser solution would be: 使用jQuery,跨浏览器解决方案将是:

var element = $('#button1');
element.removeAttr('disabled');
element.click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM