Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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 Jquery动态调用函数_Javascript_Jquery - Fatal编程技术网

Javascript Jquery动态调用函数

Javascript Jquery动态调用函数,javascript,jquery,Javascript,Jquery,我有一个场景,我必须动态调用jquery对象上的函数。代码如下所示: $('div[class]').each(function(){ var class=$(this).attr('class'); // I want to now check if that function with the name of class exists for jquery // object. I need help here. // if that function ex

我有一个场景,我必须动态调用jquery对象上的函数。代码如下所示:

$('div[class]').each(function(){
    var class=$(this).attr('class');

    // I want to now check if that function with the name of class exists for jquery
    // object. I need help here.
    // if that function exists, i need to apply that function to the enumerated object.
});

现在我想检查jQuery对象是否存在类名为的函数。我需要帮助。如果该函数存在,我需要将该函数应用于枚举对象。

我正在写这篇文章,所以它可能不起作用,但请尝试:

if(jQuery.isFunction(jQuery[class]))
     jQuery[class](this);
编辑:如果函数是jquery方法,请尝试:

 if(jQuery.isFunction(jQuery.fn[class])) {
     jQuery.fn[class](this);
     jQuery(this)[class]();    // alternative call syntax
 }

我在这里看不清您的用例。你想完成什么?解释一下,如果我这样做,那么这应该会发生!如果此元素具有类
abc
,我希望执行函数
abc
,等等。是的,如果元素具有类abc,则我希望在该元素上执行abc(如果该函数存在)。存在于全局命名空间中jQuery的
jQuery.fn.function_此处
?另外,您确定元素只有一个类吗?多个类是另一种情况。如果我有那个场景,我会解析它。我想检查它是否存在于globalspace中。我有这样的函数:$.fn.funition_name(),我想这和我想要的非常接近。非常感谢。