我正在使用这个:
$vehicleTypeDropdown = element.find(".vehicleTypeDropdown");
Then at later point of time I want to locate the #pselect
ID element.My $vehicleTypeDropdown
looks like this which is the jqLite object:-
<select class="vehicleTypeDropdown" id="vehicleType">
<option id="#pselect" value="">Please Select</option>
<option ng-repeat="types in selectedType" value="Vt3" class="ng-scope ng-binding">vt3</option>
<option ng-repeat="types in selectedType" value="Vt4" class="ng-scope ng-binding">vt4</option>
</select>
有两个问题-
.find()
方法仅查找标签,而不查找类或id。那我怎么得到$vehicleTypeDropdown = element.find(".vehicleTypeDropdown");
作为带有内容的
jqLite
对象? #pselect
选项?我想手动删除它,请记住,它可以按选项中的任何顺序排列。 最佳答案
使用不带#
的id(例如id="pselect"
)
<select class="vehicleTypeDropdown" id="vehicleType">
<option id="pselect" value="">Please Select</option>
<option ng-repeat="types in selectedType" value="Vt3" class="ng-scope ng-binding">vt3</option>
<option ng-repeat="types in selectedType" value="Vt4" class="ng-scope ng-binding">vt4</option>
</select>
捕获这样的元素
var elem = angular.element(document.querySelector('#pselect'))
elem.remove()
http://jsfiddle.net/vorant/4sbux96k/1/
关于javascript - 如何在Angualar的jqLite元素对象中按ID查找元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34975171/