如何使用jqLit​​e按类名选择元素? [英] How to select an element by classname using jqLite?

查看:25
本文介绍了如何使用jqLit​​e按类名选择元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的 Angular.js 应用程序中删除 jquery 以使其更轻,并使用 Angular 的 jqLit​​e 代替.但是该应用程序大量使用了 jqLit​​e 不支持的 find('#id') 和 find('.classname'),只有 'tag names'(根据文档)

I'm trying to remove jquery from my Angular.js app in order to make it lighter, and put Angular's jqLite instead. But the app makes heavy use of find('#id') and find ('.classname'), which are not supported by jqLite, only 'tag names' (as per documentation)

想知道您认为改变它的最佳方法是什么.我想到的一种方法是创建自定义 HTML 标签.例如:改变
<span class="btn btn-large" id="add-to-bag">添加到购物袋</span>

wondered what do u feel would be the best approach to change it. One approach I thought about is to create custom HTML tags. for example: change
<span class="btn btn-large" id="add-to-bag">Add to bag</span>

<a2b style="display:none;"><span class="btn btn-large" >Add to bag</span></a2b>

$element.find('#add-to-bag') 

$element.find('a2b')

有什么想法吗?其他想法?

Any thoughts? other ideas?

谢谢

利奥

推荐答案

本质上,正如@kevin-b 所指出的:

Essentially, and as-noted by @kevin-b:

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

//find('.classname'), assumes you already have the starting elem to search from
angular.element(elem.querySelector('.classname'))

注意:如果您希望从控制器执行此操作,您可能需要查看 开发人员指导并将您的表示逻辑重构为适当的指令(例如 <a2b ...>).

Note: If you're looking to do this from your controllers you may want to have a look at the "Using Controllers Correctly" section in the developers guide and refactor your presentation logic into appropriate directives (such as <a2b ...>).

这篇关于如何使用jqLit​​e按类名选择元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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