如何禁用使用JavaScript的HTML按钮? [英] How to disable html button using JavaScript?

查看:85
本文介绍了如何禁用使用JavaScript的HTML按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过,您可以简单地禁用(使物理上不可触摸的)html按钮,但是将禁用附加到它的标记,但不作为属性,如下所示:

I've read that you can disable (make physically unclickable) a html button simply but appending 'disable' to its tag, but not as an attribute, as follows:

<input type="button" name=myButton value="disable" disabled>

由于此设置不是属性,因此如何通过JavaScript动态添加此项以禁用按钮这是以前启用?

Since this setting is not an attribute, how can I add this in dynamically via JavaScript to disable a button that was previously enabled?

推荐答案


由于此设置不是属性

Since this setting is not an attribute

它是一个属性。

有些属性被定义为布尔值,这意味着您可以指定它们的属性价值和其他一切。即代替禁用=禁用,则只包含粗体部分。在HTML 4中,由于完整版标记为 hB.3.3rel =noreferrer>一个支持有限的功能(尽管现在当规范写出时,情况并非如此)。

Some attributes are defined as boolean, which means you can specify their value and leave everything else out. i.e. Instead of disabled="disabled", you include only the bold part. In HTML 4, you should include only the bold part as the full version is marked as a feature with limited support (although that is less true now then when the spec was written).

HTML 5的规则已经改变,现在只包含名称而不包含值。这没有实际意义,因为名称和值是相同的。

As of HTML 5, the rules have changed and now you include only the name and not the value. This makes no practical difference because the name and the value are the same.

DOM属性也被称为 disabled 和是一个布尔型,其中 true false

The DOM property is also called disabled and is a boolean that takes true or false.

foo.disabled = true;

理论上你也可以 foo.setAttribute('disabled','disabled '); foo.removeAttribute(disabled),但我不会相信这与旧版本的Internet Explorer(这是臭名昭着的当涉及到 setAttribute 时)。

In theory you can also foo.setAttribute('disabled', 'disabled'); and foo.removeAttribute("disabled"), but I wouldn't trust this with older versions of Internet Explorer (which are notoriously buggy when it comes to setAttribute).

这篇关于如何禁用使用JavaScript的HTML按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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