javascript - 如何在Angualar的jqLit​​e元素对象中通过id查找元素

标签 javascript angularjs jqlite

我正在使用这个:

$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>

有两个问题 -

  1. jqLit​​e 文档中写道,.find() 方法仅查找标签,而不查找类或 id。那么我如何获得

    $vehicleTypeDropdown = element.find(".vehicleTypeDropdown");

    作为包含内容的 jqLit​​e 对象?

  2. 如何使用 #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的jqLit​​e元素对象中通过id查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34975171/

相关文章:

javascript - 将 Angular Material Design 复选框绑定(bind)到 Controller 中的数组

javascript - .addClass 不适用于 jqLit​​e/Angular.js

javascript - jQuery DataTables 日期范围样式

javascript - 使用 HtmlService 透明的 Google App Script 背景

javascript - 如何计算给定 (x,y,z) 磁力计和加速度计数据的航向 (N/W/S/E)?

javascript - 图片重叠 div 响应问题

javascript - 在 Controller 中使用服务时使用 Angular ui-router 时出现 "Unknown Provider"错误

javascript - Bootstrap 选项卡内容/选项卡 Pane 上的 ng-repeat

javascript - Angular Directive(指令)链接功能

javascript - 单击绑定(bind)指令更新 Controller $scope 后是否需要调用 Angular 的 $apply?