Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript YAHOO.lang的jQuery版本(isUndefined、isNull、isString等)_Javascript_Jquery_Yui - Fatal编程技术网

Javascript YAHOO.lang的jQuery版本(isUndefined、isNull、isString等)

Javascript YAHOO.lang的jQuery版本(isUndefined、isNull、isString等),javascript,jquery,yui,Javascript,Jquery,Yui,有人知道jQuery插件有“helpers”或类似于中的扩展吗 我心目中的功能包括: isNull isDefined isString isFunction 对于字符串和数组,我也会很感激,比如Contains、StartsWith(我知道它们很容易编写,我只是在寻找一个包含它们的插件) 它不在YAHOO.lang名称空间中,而是与表单相关的扩展—确定radiobox的值(根据选中的值),以及友好名称中表单元素的类型 特别是使用fluent API而不是基于选择器的插件,例如 $("inpu

有人知道jQuery插件有“helpers”或类似于中的扩展吗

我心目中的功能包括:

isNull
isDefined
isString
isFunction
对于字符串和数组,我也会很感激,比如Contains、StartsWith(我知道它们很容易编写,我只是在寻找一个包含它们的插件)

它不在YAHOO.lang名称空间中,而是与表单相关的扩展—确定radiobox的值(根据选中的值),以及友好名称中表单元素的类型

特别是使用fluent API而不是基于选择器的插件,例如

$("input[@type=radio][@checked]")
我再次意识到它们很容易实现,但我不想重新发明轮子。

内置了
isFunction
isArray
(见下面的代码片段)。isString的代码是直截了当的(
typeof obj===“string”
),isNull(
obj===null
)和isDefined(
obj!==undefined
)也是如此,所以我只需要内联编写代码,而不用函数

// See test/unit/core.js for details concerning isFunction.
// Since version 1.3, DOM methods and functions like alert
// aren't supported. They return false on IE (#2968).
isFunction: function( obj ) {
    return toString.call(obj) === "[object Function]";
},

isArray: function( obj ) {
    return toString.call(obj) === "[object Array]";
},

我决定自己写两个新插件。以下是两个项目:

示例:

// elementExists is also added
if ($("#someid").elementExists())
  alert("found it");
        
// Select box related
$("#mydropdown").isDropDownList();

// Can be any of the items from a list of radio boxes - it will use the name
$("#randomradioboxitem").isRadioBox("myvalue");
$("#radioboxitem").isSelected("myvalue");
$.isNumber(42);

var x;
$.isUndefined(x);
$.isNullOrUndefined(x);
$.isString(false);

$.emptyString("the quick brown fox");
$.startsWith("the quick brown fox","the");
$.formatString("Here is the {0} and {2}","first","second");
这些是基于原型/Mochikit函数(如isNull)建模的

示例:

// elementExists is also added
if ($("#someid").elementExists())
  alert("found it");
        
// Select box related
$("#mydropdown").isDropDownList();

// Can be any of the items from a list of radio boxes - it will use the name
$("#randomradioboxitem").isRadioBox("myvalue");
$("#radioboxitem").isSelected("myvalue");
$.isNumber(42);

var x;
$.isUndefined(x);
$.isNullOrUndefined(x);
$.isString(false);

$.emptyString("the quick brown fox");
$.startsWith("the quick brown fox","the");
$.formatString("Here is the {0} and {2}","first","second");

两者都有超过50个单元测试作为下载的一部分。希望它们对查找此页面的用户有用。

如果您愿意,可以使用包含这些函数的库。

typeof String(“foo”)=“object”