document.getElementById('btnid')。disabled在firefox和chrome中不起作用 [英] document.getElementById('btnid').disabled is not working in firefox and chrome

查看:825
本文介绍了document.getElementById('btnid')。disabled在firefox和chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JavaScript来禁用按钮。在IE中工作正常,但在FireFox和chrome中没有,这是我正在处理的脚本:

I'm using JavaScript for disabling a button. Works fine in IE but not in FireFox and chrome, here is the script what I'm working on:

function disbtn(e) { 
    if ( someCondition == true ) {
       document.getElementById('btn1').disabled = true;
    } else {
       document.getElementById('btn1').disabled = false;
    }

在我的html中我有:

And in my html I have:

<input type="button" id="btn1" value="submit" />


推荐答案

使用 setAttribute() removeAttribute()

function disbtn(e) { 
    if ( someCondition == true ) {
       document.getElementById('btn1').setAttribute("disabled","disabled");
    } else {
       document.getElementById('btn1').removeAttribute("disabled");
    }
}

查看演示

这篇关于document.getElementById('btnid')。disabled在firefox和chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆