如何设置“标签”的 id HTML 元素?
如果我有以下内容:
<label for="deletetxt">Delete This Text</label>
这里的“for”属性是什么?是这个id吗?
假设我无法为标签元素设置类来设置标签元素的样式,我该如何为此元素设置CSS?
If I have the following:
<label for="deletetxt">Delete This Text</label>
What is the 'for' attribute here? Is that the id?
Assuming that I cannot set a class for the label element to style the label element, how do i set css for this element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
for
属性包含标签所属元素的 ID。我一直认为这会非常直观...您可以像任何其他元素一样设计标签:
我一直认为这也非常直观。那么 - 您真正想要做什么,您提出的问题实际上表明您遇到了不同的问题。
The
for
attribute contains the ID of the element that the label is for. I always thought this would be quite intuitive...You style a label like any other element:
I always thought this would be quite intuitive, as well. So - what are you really trying to do, the questions you ask are a sign that you have a different problem, actually.
两个问题,两个答案:
这里的“for”属性是什么?
它在这里告诉 label 引用的
元素的 ID。当用户单击
时,某些浏览器将使用它来将焦点设置在该
元素上。
如何为此元素设置 css?
A.如果您想对所有标签元素使用 CSS:
B. 如果您想标记该元素,只需像平常一样使用 ID 或类名即可。
Two question, two answers:
What is the 'for' attribute here?
It's here to tell the ID of the
<input>
element that label refers to. Some browsers will use it to set focus on that<input>
element when user clicks on that<LABEL>
how do i set css for this element?
A. If you want to CSS all label elements :
B. If you want to label that element, just use IDs or classnames as you usually do.
for 属性是标签引用的 input/textarea/select。
您仍然可以为标签分配 id:
您还可以使用标签包装 input/textarea/select,以便在不使用 for 属性的情况下将它们关联起来。
The for attribute is the input/textarea/select that the label refers to.
You can still assign an id to the label:
You can also wrap the input/textarea/select with the label in order to associate them without the for attribute.
For
告诉标签属于哪个元素(这实际上意味着当单击标签时该元素将获得焦点)。至于你的第二个问题 - 你可以使用 jQuery:
- 如果您的 html 是静态的,请使用
$("label:eq(index)")
- 如果您的 html 是动态的并且您知道标签所属元素的 id,则可以使用
$("label[for='thatid']")
The
For
tells the label which element to belong to (which really means that when the label is clicked the element will get the focus).As for your second question - you can use jQuery:
- If your html is static use
$("label:eq(index)")
- If your html is dynamic and you know the id of the element the label belongs to, you can use
$("label[for='thatid']")
HTML Label Tag 用于表单和提交。它不是 ID,这个“for”应该与连接到它的对象的 ID 具有相同的名称 - 例如,
它确实是一个可用性对象。
HTML Label Tag is used for forms and submittion. it is not the ID, this 'for' should have the same name as the ID of the object connected to it - for example
Its a usability object really.
“for”是标签应关联的表单元素的 id。
您可以在标签中添加 id 以直接引用它。
"for" is the id of the form element that the label should be associated with.
You can add an id to the label to reference it directly.
您可以设置 id 和类 http://www.w3schools.com/tags/ tag_label.asp
用于“指定标签绑定到哪个表单元素”,因此当用户单击标签时,它会关注目标输入。
you can set an id as well as a class http://www.w3schools.com/tags/tag_label.asp
the for "Specifies which form element a label is bound to" so when a user clicks on the label it focuses on the target input.
使用 Html 中的 razor,我找不到分配标签 id 的最佳方法,但您可以通过以下方式分配 id:
With razor in Html I don´t find the best way for assign the id of a label, but you can assign the id in this way: