本文主要介绍了angularjs中下拉框的基本用法,结合具体实例形式分析了angularjs下拉框的元素绑定、选中及显示等功能实现方法,需要的朋友可以参考下,希望能帮助到大家。
html正文:
<p ng-app="myapp" ng-controller="myctrl">
<select ng-model="selectedname" ng-options="x for x in names"></select>
等价于:
<select>
<option ng-repeat="item in names">{{item}}</option>
</select>
<hr>
<!-- ng-repeat绑定的值为一个字符串,ng-options绑定的为一个对象 -->
<select ng-model="selectedsite">
<option ng-repeat="item in sites" value="{{item.url}}">{{item.site}}</option>
</select>
<span>你选中的选址:{{selectedsite}}</span>
<br><br>
<select ng-model="selectedsite" ng-options="x.site for x in sites"></select>
<span>你选中的选址:{{selectedsite}}</span>
<hr>
<!-- 因为对象数组没有key,angular默认使用数组的下标值作为key显示 -->
<select ng-model="aaaa" ng-options="x for (x, y) in sites"></select>
<span>你选择的值是: {{aaaa}}</span>
</p>
javascript操作代码:
var app = angular.module('myapp', []);
app.controller('myctrl', function($scope) {
$scope.names = ["google", "baidu", "taobao"];
$scope.sites = [{
site : "google", url : "http://www.google.com"},
{site : "baidu", url : "http://www.baidu.com"},
{site : "taobao", url : "http://www.taobao.com"} ];
});
效果:
相关推荐:
angularjs中下拉框的高级用法实例讲解
js和jquery以及easyui实现对下拉框的指定赋值实例分享
jquery模拟下拉框选择对应菜单
以上就是angularjs中下拉框的基本用法详解的详细内容。