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

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

问题描述

我正在尝试从Angular.js应用中删除jquery,以使其更轻巧,而改用Angular的jqLit​​e.但是该应用程序大量使用了jqLit​​e不支持的find('#id')和find('.classname'),仅使用了标签名称"(根据文档)

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">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'))

注意::如果您希望从控制器中执行此操作,则可能需要查看

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天全站免登陆