且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery的触发相当于angularjs

更新时间:2022-06-23 05:32:02

AngularJS有jqLit​​e内置到它。请参考文档以查看可用的方法,

AngularJS has jqLite built into it. Refer the docs to see the available methods,

角jqLit​​e

为您的方案:

$不会angularJS工作,angular.element是$等效。
但jqLit​​e是非常有限不支持的ID选择器,意思是,你不能简单地使用angular.element通过class和id选择一个元素一样,

$ will not work in angularJS, angular.element is the equivalent of $. but jqLite being very limited does not support "selectors by id" meaning you cannot simply use angular.element to select an element by class or id like,

var element = angular.element('#foo')

您必须使用以下

var element = angular.element(document.querySelector('#foo'))

您可能会问,为什么不使用的document.getElementById('#富')?但请记住,我们正在使用jqLit​​e,所以我们必须使用angular.element,以便能够使用元素的jqLit​​e方法。

You may ask, "why not use document.getElementById('#foo')?" but remember we are using jqLite so we have to use angular.element in order to be able to use the jqLite methods on the element.

您可以使用.triggerHandler()而不是.trigger()。 jQuery的triggerHandler文档

you can use the .triggerHandler() instead of .trigger(). jQuery triggerHandler docs

jqLit​​e不支持点击()。解决方法是使用。就绪()

jqLite does not support click(). The workaround would be to use .ready()

element.ready(function() {
    console.log('Click');
});