“for”属性的目的是什么?
16lz
2021-01-22
In this code taken from angular.org:
在此代码取自angular.org:
<script>
function Ctrl($scope) {
$scope.names = ['pizza', 'unicorns', 'robots'];
$scope.my = { favorite: 'unicorns' };
}
</script>
<form ng-controller="Ctrl">
<h2>Which is your favorite?</h2>
<label ng-repeat="name in names" for="{{name}}">
{{name}}
<input type="radio"
ng-model="my.favorite"
ng-value="name"
id="{{name}}"
name="favorite">
</label>
<div>You chose {{my.favorite}}</div>
</form>
the label element has a "for" statement. I can't find anything on the Angular.org site indicating what this is or how it is used. It's not listed under directives or functions.
label元素有一个“for”语句。我在Angular.org网站上找不到任何内容,说明这是什么或如何使用。它没有列在指令或功能下。
2 个解决方案
#1
2
Just adding to the comments in the previous answer:
只需添加上一个答案中的评论:
The for
attribute is used to target the input
when the label
and input are separate, like so:
当标签和输入是分开的时,for属性用于定位输入,如下所示:
<label for="MyId">
My Label
</label>
<input type="radio"
id="MyId"
name="favorite">
If you nest the input
inside the label
like your example:
如果您将输入嵌套在标签内,就像您的示例:
<label>
My Label
<input type="radio"
name="favorite">
</label>
Then you don't need the for
attribute, it will automatically target the input inside the label.
然后你不需要for属性,它会自动定位标签内的输入。
更多相关文章
- struts2和struts1.x的标签库
- HTML标签p和div的不同
- Android里string.xml使用html标签的方法
- 标签滑块旋转木马不工作在引导4
- {{content}}液体标签未显示博客帖子
- 【HTML5】H5新标签大实例 可直接运行
- 一天搞定HTML----标签类型与类型转换05
- HTML5实战与剖析之媒体元素(1、video标签和audio标签简介)
- 如何控制html代码中DL标签的颜色?