Can jQuery and Mootools work together?

后端 未结 5 954
庸人自扰
庸人自扰 2021-01-18 11:21

Can jQuery and Mootools work together??

If not when is that case?

5条回答
  •  猫巷女王i
    2021-01-18 12:14

    There's more to it than just noConflict.

    jQuery is an intrusive library. It adds an internal jQuery123 (for some randomised per-instance value of 123) property to every element it touches (which is anything with data or event handlers, amongst other reasons). In IE, this property also gets reflected as an attribute.

    So if MooTools or any other library (or indeed, a plain DOM method) comes along and starts messing with those properties/attributes, or cloning elements, or hacking innerHTML, they're likely to mess up these supposedly-unique identifiers, causing jQuery to get confused and start misbehaving in ways it is extraordinarily difficult to debug.

    jQuery also fiddles a bunch of event code to try to make submit/focus/blur/focusin/focusout/mouseenter/mouseleave events work and bubble across browsers. This may confuse other-library code that is not expecting it.

    So, with jQuery 1.4, you can just about get away with using another library at the same time, as long as they are working on separate elements that don't interact with each other. (jQuery 1.3 was also much more promiscuous about what elements it ‘touched’.)

    But in general I would not recommend two major frameworks on one page.

提交回复
热议问题