AngularJS - 查找元素根据属性值 [英] AngularJS - Find Element by Attribute Value

查看:1676
本文介绍了AngularJS - 查找元素根据属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用AngularJS查询我的观点的DOM。我需要得到所有具有属性数据布局与顶级的价值元素。 jQuery中,我会做这样的:

I'm trying to use AngularJS to query the DOM of my view. I need to get all of the elements that have the attribute 'data-placement' with the value of 'top'. In jQuery, I would do this:

var elements = $('[data-placement="top"]');

不过,我不知道如何与AngularJS做到这一点。谁能告诉我如何做到这一点?

However, I don't know how to do it with AngularJS. Can someone tell me how to do this?

感谢您!

推荐答案

在AngularJS你不会从控制器直接做DOM操作,你应该创建一个指令到。该指令内部如你所愿,你可以使用jQuery。

In AngularJS you won't do direct DOM manipulation from the controller, you should create a directive to to that. Inside the directive you can use JQuery as you wish.

反正你我想你可以使用 angular.element()与JQlite选择,这里的的 angular.element

Anyway you I think you can use angular.element() with a JQlite selector, here's the documentation of angular.element.

例如:

// find('#id')
angular.element(document.querySelector('#id'))

这篇关于AngularJS - 查找元素根据属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆