Html 如何禁用类型为提交的输入元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8893111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:34:44  来源:igfitidea点击:

How do I disable input element whose type is submit?

htmlinput

提问by CppLearner

I know the following works:

我知道以下作品:

<input type="text" disabled="disabled" />
<button disabled="disabled"> 

But how would you disable this?

但是你将如何禁用它?

<input type="submit" ....>

Any idea? Do I have to use javascript?

任何的想法?我必须使用 javascript 吗?

Thanks.

谢谢。



Okay. It might have been my Firefox problem. I swear I did use the same synatx. Thanks, and sorry for such a silly question?

好的。这可能是我的 Firefox 问题。我发誓我确实使用了相同的 Synatx。谢谢,抱歉问这么愚蠢的问题?

回答by Curt

You can use disabled="disabled"on input's that are of type submit:

您可以使用以下类型的disabled="disabled"on :inputsubmit

<input type="submit" disabled="disabled" />

回答by Mathias Bynens

Just use:

只需使用:

<input type="submit" disabled>

Here's a demo: http://jsbin.com/agojoy/edit#html,live

这是一个演示:http: //jsbin.com/agojoy/edit#html,live

Note that disabledis a boolean attribute. There are variations in syntax, but they all have the same effect:

请注意,这disabled是一个布尔属性。语法有多种变化,但它们都具有相同的效果:

<input type="submit" disabled=disabled>
<input type="submit" disabled="disabled">
<input type="submit" disabled="disabled"/>
<input type="submit" disabled="disabled" />

回答by Oded

In order to dynamically disable a button, you do need to use javascript.

为了动态禁用按钮,您需要使用 javascript。

Attach to the click event and set the control to disabled.

附加到单击事件并将控件设置为禁用。

If you just want to do so in the HTML, the disabledattribute works just as well:

如果您只想在 HTML 中这样做,该disabled属性也能正常工作:

<input type="submit" disabled="disabled" />