AngularJS強(qiáng)化了前端的MVC邏輯,卻弱化了Jquery的Dom操作能力崔赌。
好在Angular自身也考慮到這個(gè)問(wèn)題秀姐,所以它自身內(nèi)置了jqLite來(lái)彌補(bǔ)這方面的不足痒留。
同時(shí)它提供了jqlite的封裝方法:angular.element(ele)匾效,相當(dāng)于jquery的$
但建議使用時(shí)可以在全局處設(shè)置
`var $ = function(ele){
if(typeof ele == "string"){
ele = document.querySelectorAll(ele);
}
return angular.element(ele);
};
但jqLite只有一部分Jquery的語(yǔ)法扫步,很多小伙伴可能都找不到j(luò)qlite的API,所以我這里就列舉一下
* jqLite provides only the following jQuery methods:
*
* – [`addClass()`](http://api.jquery.com/addClass/)
* – [`after()`](http://api.jquery.com/after/)
* – [`append()`](http://api.jquery.com/append/)
* – [`attr()`](http://api.jquery.com/attr/)
* – [`bind()`](http://api.jquery.com/on/) – Does not support namespaces, selectors or eventData
* – [`children()`](http://api.jquery.com/children/) – Does not support selectors
* – [`clone()`](http://api.jquery.com/clone/)
* – [`contents()`](http://api.jquery.com/contents/)
* – [`css()`](http://api.jquery.com/css/)
* – [`data()`](http://api.jquery.com/data/)
* – [`empty()`](http://api.jquery.com/empty/)
* – [`eq()`](http://api.jquery.com/eq/)
* – [`find()`](http://api.jquery.com/find/) – Limited to lookups by tag name
* – [`hasClass()`](http://api.jquery.com/hasClass/)
* – [`html()`](http://api.jquery.com/html/)
* – [`next()`](http://api.jquery.com/next/) – Does not support selectors
* – [`on()`](http://api.jquery.com/on/) – Does not support namespaces, selectors or eventData
* – [`off()`](http://api.jquery.com/off/) – Does not support namespaces or selectors
* – [`one()`](http://api.jquery.com/one/) – Does not support namespaces or selectors
* – [`parent()`](http://api.jquery.com/parent/) – Does not support selectors
* – [`prepend()`](http://api.jquery.com/prepend/)
* – [`prop()`](http://api.jquery.com/prop/)
* – [`ready()`](http://api.jquery.com/ready/)
* – [`remove()`](http://api.jquery.com/remove/)
* – [`removeAttr()`](http://api.jquery.com/removeAttr/)
* – [`removeClass()`](http://api.jquery.com/removeClass/)
* – [`removeData()`](http://api.jquery.com/removeData/)
* – [`replaceWith()`](http://api.jquery.com/replaceWith/)
* – [`text()`](http://api.jquery.com/text/)
* – [`toggleClass()`](http://api.jquery.com/toggleClass/)
* – [`triggerHandler()`](http://api.jquery.com/triggerHandler/) – Passes a dummy event object to handlers.
* – [`unbind()`](http://api.jquery.com/off/) – Does not support namespaces
* – [`val()`](http://api.jquery.com/val/)
* – [`wrap()`](http://api.jquery.com/wrap/)