mootools 选择器

    技术2022-07-11  144

    mootools 选择器

    A few weeks back I touched on how you could implement the Peppy and Sizzle selector engines in MooTools. Both posts showed how to remove the default Moo engine from use and instead make each respective selector engine the one and only. It doesn't have to be that way. You could use all three engines within the page as well.

    几周前,我谈到了如何在MooTools中实现Peppy和Sizzle选择器引擎。 这两篇文章都展示了如何从使用中删除默认的Moo引擎,而是使每个选择器引擎成为唯一的选择器引擎。 不一定要那样。 您也可以在页面中使用所有三个引擎。

    Peppy,Sizzle和Moo在一起 (Peppy, Sizzle, and Moo Together)

    //assuming that the JavaScript files we brought in via simple XHTML above... /* MooTools */ var divs = $$('div'); /* Sizzle */ Window.$Sizzle = function(selector){ return new Elements(new Sizzle(selector)); } //sizzle usage var divs = $Sizzle('div'); /* Peppy */ Window.$Peppy = function(selector){ return new Elements(new peppy.query(selector)); } //Peppy usage var divs = $Peppy('div');

    Why do this? Each engine has its advantages. Sizzle generally does better with Internet Explorer so if you detect that the user is using IE, you may want to use Sizzle to grab the elements instead.

    为什么这样 每个引擎都有其优势。 Sizzle通常在Internet Explorer上做得更好,因此,如果您检测到用户正在使用IE,则可能要使用Sizzle来获取元素。

    In most cases the overhead of bringing in each engine makes this strategy overkill. It's definitely an option though.

    在大多数情况下,引入每个引擎的开销使该策略变得过大。 当然,这绝对是一个选择。

    翻译自: https://davidwalsh.name/mootools-peppy-sizzle

    mootools 选择器

    相关资源:Mootools 1.2教程(2) DOM选择器
    Processed: 0.011, SQL: 10