Sha*_*ram 5 javascript angularjs
大家好
我试图从按钮单击的选择框中获取选项值,但它在控制台中显示未定义.Options值来自服务器
这是我的HTML代码
<div class="form-group">
<label class="control-form" for="cityid">Selct City</label>
<select type="text" class="form-control" placeholder="City" id="acity" >
<option value="">--Select City--</option>
<option ng-repeat="city in cityinfo" ng-value="{{city.id}}" ng-selected="{{city.id ==cityid}}">{{city.cityname}}</option>
</select>
<button class="btn btn-info prevnext pull-right" ng-click="nextpage()">Next <i class="fa fa-arrow-right"></i></button>
Run Code Online (Sandbox Code Playgroud)
Controller.js文件代码
$scope.nextpage = function(pageno) {
console.log($scope.cityinfo);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
Roy*_*Roy 10
用ng-options
而不是ng-repeat
.
像这样:
更新
<select type="text" class="form-control" placeholder="City" id="acity" ng-options="city.id as city.cityname for city in cityinfo track by city.id" ng-model="selectedCity">
<option value="">--Select City--</option>
</select>
<button class="btn btn-info prevnext pull-right" ng-click="nextpage(selectedCity)">Next <i class="fa fa-arrow-right"></i></button>
Run Code Online (Sandbox Code Playgroud)
JS:
$scope.nextpage = function(selectedCity){
console.log(selectedCity);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19107 次 |
最近记录: |