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属性,它会自动定位标签内的输入。

更多相关文章

  1. struts2和struts1.x的标签库
  2. HTML标签p和div的不同
  3. Android里string.xml使用html标签的方法
  4. 标签滑块旋转木马不工作在引导4
  5. {{content}}液体标签未显示博客帖子
  6. 【HTML5】H5新标签大实例 可直接运行
  7. 一天搞定HTML----标签类型与类型转换05
  8. HTML5实战与剖析之媒体元素(1、video标签和audio标签简介)
  9. 如何控制html代码中DL标签的颜色?

随机推荐

  1. 疯狂XML学习笔记(3)-----------XML与DTD
  2. android如何使用DOM和SAXParserFactory来
  3. XML简明教程(2)
  4. android使用XmlPullParser来解析XML文件
  5. XML简明教程(1)
  6. 疯狂XML学习笔记(2)-------------格式要求
  7. android使用Gson来解析json
  8. 疯狂XML学习笔记(1)------------初识
  9. IOS解析XML文件
  10. XPath技术