2016-02-05 22 views
0

我正在研究phonegap.jquery移動版,Angularjs移動應用程序如何在範圍函數內觸發selectbox單擊?

我想點擊一下鼠標點擊一下其他圖標。爲此,我打電話給一個範圍函數,從他們我嘗試過$('#id')。click();但它不適合我。

<div id="clickforsele" ng-click="selectdisplay()"> 

選擇框是 <select id="seleid"><options....... </select>

和範圍功能$scope.selectdisplay = function() { $('#seleid').click(); }

談到範圍功能。但從我不能觸發點擊。有人可以幫助我?

回答

-1

你的目標究竟是什麼?要打開select元素?選擇一個項目?

如果你需要選擇一個項目:只要使用NG選項指令https://docs.angularjs.org/api/ng/directive/ngOptions

在HTML

<select ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select> 

在你的控制器:

$scope.selected = null;// initialize this is important you may have trouble if you forget this 
$scope.items = []; // same better to init them as empty array 1st if your doing an asynchrnous request to load them after 
$scope.selectdisplay = function() { $scope.selected = $scope.items[1]}// set the second element as selected. 

現在,如果你想只打開選擇框我建議你查看這個帖子How to open select programmatically