AngularJS动态生成div的ID
程序员文章站
2024-04-05 23:42:19
...
1、问题背景
给定一个数组对象,里面是p的id;循环生成p元素,并给id赋值
2、实现源码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>AngularJS动态生成p的ID</title> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <script> var app = angular.module("idApp",[]); app.controller("idCon",function($scope){ $scope.pIds = [ {pId:"chartId1"}, {pId:"chartId2"}, {pId:"chartId3"}, {pId:"chartId4"}, {pId:"chartId5"} ]; }); </script> </head> <body ng-app="idApp" ng-controller="idCon"> <p ng-repeat="chart in pIds"> <p id="{{chart.pId}}">{{chart.pId}}</p> </p> </body> </html>
3、实现结果
<html><head><style type="text/css">@charset "UTF-8"; [ng\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak], .ng-cloak, .x-ng-cloak, .ng-hide:not(.ng-hide-animate){ display:none !important;}ng\:form{display:block;} .ng-animate-shim{visibility:hidden;} .ng-anchor{position:absolute;}</style> <meta charset="UTF-8"> <title>angularJS动态生成p的ID</title> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <script> var app = angular.module("idApp",[]); app.controller("idCon",function($scope){ $scope.pIds = [ {pId:"chartId1"}, {pId:"chartId2"}, {pId:"chartId3"}, {pId:"chartId4"}, {pId:"chartId5"} ]; }); </script> </head> <body ng-controller="idCon" ng-app="idApp" class="ng-scope"> <!-- ngRepeat: chart in pIds --><p ng-repeat="chart in pIds" class="ng-scope"> <p id="chartId1" class="ng-binding">chartId1</p> </p><!-- end ngRepeat: chart in pIds --><p ng-repeat="chart in pIds" class="ng-scope"> <p id="chartId2" class="ng-binding">chartId2</p> </p><!-- end ngRepeat: chart in pIds --><p ng-repeat="chart in pIds" class="ng-scope"> <p id="chartId3" class="ng-binding">chartId3</p> </p><!-- end ngRepeat: chart in pIds --><p ng-repeat="chart in pIds" class="ng-scope"> <p id="chartId4" class="ng-binding">chartId4</p> </p><!-- end ngRepeat: chart in pIds --><p ng-repeat="chart in pIds" class="ng-scope"> <p id="chartId5" class="ng-binding">chartId5</p> </p><!-- end ngRepeat: chart in pIds --> </body></html>
以上就是AngularJS动态生成p的ID的内容,更多相关内容请关注PHP中文网(www.php.cn)!
相关文章:
推荐阅读
-
AngularJS动态生成div的ID
-
php如何生成动态的表格,表头和数据都是动态的?
-
请问CSDN 的 ID 是如何生成的?
-
用动态网页技术PHP生成验证码图片的源代码_PHP教程
-
php动态生成版权所有信息的方法,php动态生成版权所有
-
php根据数据id自动生成编号的实现方法
-
PHP动态生成指定大小随机图片的方法
-
CSS生成div的闪烁特效
-
调查问卷动态生成的一点探索 博客分类: Java编程jsonjqueryjavascript jqueryjsonspring restfulmango dbajax
-
Java编程的动态特性,使用BCEL代码生成工具,极大简化Class Transformation开发 Java字节码虚拟机BCELClassTransformer