AngularJS 可以使用數(shù)組或?qū)ο髣?chuàng)建一個(gè)下拉列表選項(xiàng)。
AngularJS Select(選擇框) 語(yǔ)法
在 AngularJS 中我們可以使用?ng-option?指令來(lái)創(chuàng)建一個(gè)下拉列表,列表項(xiàng)通過(guò)對(duì)象和數(shù)組循環(huán)輸出
AngularJS Select(選擇框) 示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script> </head> <body> <div ng-app="myApp" ng-controller="myCtrl"> <select ng-init="selectedName = names[0]" ng-model="selectedName" ng-options="x for x in names"> </select> </div> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.names = ["Google", "php.cn", "Taobao"]; }); </script> <p>該實(shí)例演示了 ng-options 指令的使用。</p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例