jQuery的有用的未记录方法和属性 [英] Useful undocumented methods and properties of jQuery

查看:58
本文介绍了jQuery的有用的未记录方法和属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想收集 jQuery 的所有有用未记录的方法和属性(至少对于当前版本1.9.0 ).

I would like to gather all useful undocumented methods and properties of jQuery (at least for the current version 1.9.0).

对于解决特定问题或加速JavaScript代码评估,其中某些人看起来很有前途.

Some of them look quite promising either for solving particular problems, or for accelerating the JavaScript code evaluation.

重要提示::由于此处未列出列出的功能,因此应谨慎使用,因为新版本的jQuery在将来的版本中可能不支持这些功能.

Important: Since the listed features here are not documented, it should be used with caution, as new versions of jQuery might not support these features in future releases.

推荐答案

用于保存活动查询数的计数器

Counter for holding the number of active queries

当需要检查正在运行的Ajax请求的数量时,此属性很有用.例如,以下代码可以用于防止双重Ajax请求:

This property is useful when there is a need to check the number of running Ajax requests. For example, the following code can be used to prevent double Ajax request:

$("button").on("click", function() {
    if ($.active.length === 0) {
        $.ajax({ ... });
    }
});


$ .camelCase(字符串)


$.camelCase(string)

将破折号转换为camelCase

Convert dashed to camelCase

虽然jQuery在 css data 模块中使用此方法,但是您可以使用它将格式为xxx-yyy-zzz的字符串转换为xxxYyyZzz:

While jQuery uses this method in css and data modules, you can use it to transform strings in format xxx-yyy-zzz to xxxYyyZzz:

var str = $.camelCase("xxx-yyy-zzz");  // "xxxYyyZzz


$ .easing

此属性包含所有受支持的缓动效果以及用于计算这些效果的函数.默认情况下,jQuery仅支持linearswing效果,但是如果包含 jQueryUI $.easing属性将扩展了其他效果.


$.easing

This property contains all supported easing effects with functions for calculating these effects. By default jQuery supports linear and swing effects only, but if you include jQueryUI $.easing property will be extended with other effects.

例如,我们可以轻松地通过以下代码检查弹跳效果:

For instance, we can easily check if bounce effect is supported with the following code:

var bounceSupported = "easeInOutBounce" in $.easing;


$ .isReady


$.isReady

DOM准备好使用了吗?设置为true.

Is the DOM ready to be used? Set to true once it occurs.

如果出于某种原因您不使用$(document).ready()事件,则此属性可以用作检查DOM是否已完全加载的标志.到目前为止简单的例子:

This property can be used as a flag to check if DOM was fully loaded, if for some reason you don't use $(document).ready() event. Easy example so far:

if (!$.isReady) {
    $.error("DOM was not fully loaded yet");
}


$ .readyWait


$.readyWait

一个计数器,用于跟踪准备事件发生之前要等待多少个项目 起火.

A counter to track how many items to wait for before the ready event fires.

但是我发现除了与$.isReady相同以外,没有其他用途.

Yet I found no other use except the same as for $.isReady.

实用程序函数,用于检索DOM数组的文本值 节点.

Utility function for retrieving the text value of an array of DOM nodes.

从DOM树中拾取文本内容的快速方法.当您需要加速代码并与DOM元素一起使用时,它很有用:

Fast method for picking up text contents from DOM tree. It is useful when you need to speed up your code, that works with DOM elements:

$("div").on("click", function() {
    console.log( $.text(this) );
});


$ .timers

此属性保存jQuery元素动画的计时器.它可以用于快速检查一次是否有任何动画进程在运行,而不是$(":animated").length:


$.timers

This property holds timers of jQuery elements animation. It can be used for fast check if there is any animation process running at a time, instead of $(":animated").length:

$("span").on("click", function() {
    if ($.timers.length === 0) {
        $(".flows, #spoiler, #par > p").fadeIn("slow");
    }
});

可以从此问题中获得一个很好的用法示例.

One good usage example can be taken from this question.

此方法的行为与Array.push()相同,将新的DOM元素添加到jQuery对象.与$a = $a.add($b)一样:

This method behaves in the same way as Array.push(), adding new DOM element to jQuery object. Does the same as $a = $a.add($b):

var $a = $("#element1"),
    $b = $("#element2");

$a.push($b[0]);

用法示例:选择器的jQuery串联而不创建新实例?

这篇关于jQuery的有用的未记录方法和属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆