admin管理员组文章数量:1310461
Is it possible? No matter how, in Javascript or jQuery.
For example: $.isFunction($.isFunction());
Upd: But how to check method of a jQuery plugin? Sometimes it not ready at the moment of it call and generates error. Example: $.isFunction($().jqGrid.format)
Is it possible? No matter how, in Javascript or jQuery.
For example: $.isFunction($.isFunction());
Upd: But how to check method of a jQuery plugin? Sometimes it not ready at the moment of it call and generates error. Example: $.isFunction($().jqGrid.format)
2 Answers
Reset to default 8To pass a function to another function, leave the ()
off:
$.isFunction($.isFunction); // true!
When you write ()
you are calling the function, and using the result it returns. $.isFunction()
with no argument returns false
(because undefined
isn't a function), so you are saying $.isFunction(false)
, which is, naturally, also false
.
I wouldn't bother using isFunction
merely to check for the existence of something, unless you suspect that someone might have assigned a non-function value to it for some reason. For pure existence-checking, use the in
operator:
if ('isFunction' in $) { ...
Yes,
jQuery.fn.exists = function(){return jQuery(this).length>0;}
if ($(selector).exists()) {
// code........
}
本文标签: javascriptCheck if jQuery method existsStack Overflow
版权声明:本文标题:javascript - Check if jQuery method exists - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741825784a2399631.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论