什么是HTML代表=“"” < label>中的属性? [英] What is the HTML for="" attribute in <label>?

查看:118
本文介绍了什么是HTML代表=“"” < label>中的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < label for =name>文字< / label> 
< input type =textname =namevalue =/>


解决方案

c $ c>属性用于标签。它指的是与这个标签相关的元素的id。



例如:

 < label for =username>使用者名称< / label> 
< input type =textid =usernamename =username/>

现在,当用户用鼠标点击用户名文本浏览器会自动将焦点放在相应的输入字段中。这也适用于其他输入元素,例如< textbox> < select>



来自规范


该属性明确地将定义的标签与另一个控件
相关联。如果存在,则此属性的值必须是
,与
同一文档中某个其他控件的id属性的值相同。当缺席时,被定义的标签与
元素的内容相关联。


至于为什么您的问题被标记为jQuery和你在哪里看到它被用于jQuery我无法回答,因为你没有提供太多的信息。

也许它被用在jQuery选择器中,以给定一个标签实例来查找相应的输入元素:

  var label = $('label'); 
label.each(function(){
//获取标签的相应输入元素:
var input = $('#'+ $(this).attr('for' ));
});


I have seen this in jQuery - what does it do?

<label for="name"> text </label>
<input type="text" name="name" value=""/>

解决方案

The for attribute is used in labels. It refers to the id of the element this label is associated with.

For example:

<label for="username">Username</label>
<input type="text" id="username" name="username" />

Now when the user clicks with the mouse on the username text the browser will automatically put the focus in the corresponding input field. This also works with other input elements such as <textbox> and <select>.

Quote from the specification:

This attribute explicitly associates the label being defined with another control. When present, the value of this attribute must be the same as the value of the id attribute of some other control in the same document. When absent, the label being defined is associated with the element's contents.

As far as why your question is tagged with jQuery and where did you see it being used in jQuery I cannot answer because you didn't provide much information.

Maybe it was used in a jQuery selector to find the corresponding input element given a label instance:

var label = $('label');
label.each(function() {
    // get the corresponding input element of the label:
    var input = $('#' + $(this).attr('for'));
});

这篇关于什么是HTML代表=“&quot;” &lt; label&gt;中的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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