Javascript 如何在javascript中禁用标签标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6149168/
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
how to disable a label tag in javascript
提问by mere
i need to create five labels using <label>
tag in html. then when any one of the label is clicked all the other four labels must be disabled. i have searched through the google but could not find how to disable label tag. is there any way to do that .any suggestion......
我需要使用<label>
html 中的标签创建五个标签。然后,当单击任何一个标签时,必须禁用所有其他四个标签。我已经通过谷歌搜索,但找不到如何禁用标签标签。有没有办法做到这一点。任何建议......
<label for="u">username1</label>
<label for="u">username2</label>
<label for="u">username3</label>
<label for="u">username4</label>
<label for="u">username5</label>
回答by Ivan Santiago
You can see in the source a whole solution using Javascript and CSS. But if you want labels "look" like disabled you can use CSS this way:
您可以在源代码中看到使用 Javascript 和 CSS 的完整解决方案。但是如果你想让标签“看起来”像被禁用,你可以这样使用 CSS:
In HTML
在 HTML 中
<label class="disabled" for="u">username1 </label>
In CSS
在 CSS 中
label.disabled { color: #aaa; }
回答by Quentin
Before looking at your example, I would have said:
在看你的例子之前,我会说:
A label can't be disabled. One of the effects it has is to extend the click target of a form control, so you probably want to disable the form control instead.
无法禁用标签。它的作用之一是扩展表单控件的单击目标,因此您可能希望禁用表单控件。
However, for some reason, all your labels are associated with the same control (the one with id="u"
), which suggests that you aren't using <label>
correctly. It is possible to have multiple labels for a single control, but it doesn't look like you are doing that.
但是,出于某种原因,您的所有标签都与同一个控件(带有 的控件id="u"
)相关联,这表明您没有<label>
正确使用。单个控件可以有多个标签,但看起来您并没有这样做。
You should probably take a step back and describe the problem that you think disabling a label will solve.
您可能应该退后一步,描述您认为禁用标签可以解决的问题。
回答by Sai Kalyan Kumar Akshinthala
You, cant disable the Labels. Instead u can set the Text property of the label to ""
when one label is clicked for the other ones.
你,不能禁用标签。相反,您可以将标签的 Text 属性设置""
为单击另一个标签的时间。