Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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 未捕获的TypeError:$(…)。另一个Func不是函数_Javascript_Jquery - Fatal编程技术网

Javascript 未捕获的TypeError:$(…)。另一个Func不是函数

Javascript 未捕获的TypeError:$(…)。另一个Func不是函数,javascript,jquery,Javascript,Jquery,flip.js效果正常,flip:done内的console.log也正常,但名为inside flip:done的“anotherfunc”不正常。请帮忙 function anotherfunc( ) { console.log("its anotherfunc"); } jQuery(document).ready(function($) { //it is working here but not inside flip:done anotherfunc(); $(".c

flip.js效果正常,flip:done内的console.log也正常,但名为inside flip:done的“anotherfunc”不正常。请帮忙

function anotherfunc( ) {
    console.log("its anotherfunc");
}


jQuery(document).ready(function($) {

//it is working here but not inside flip:done
anotherfunc();

$(".card").flip({
    trigger:  'hover',
    speed : 1000
});


$(".card").on('flip:done',function(  ){

  // this is also working
  console.log('from inside flip:done');

  // this is also working
  console.log( $(this) ); 


  // this is saying "is not a function"
  $(this).anotherfunc();

});


});//on laod

是的,anotherfunc是一个函数,但是没有调用
$(this)

如果要向其传递对象,则在顶部作用域上声明anotherfunc()

 function anotherfunc(myobject) {
 ....
}
并将其命名为
$(this)


请确保清除myobject是否允许为null

您可以将其称为

anotherfunc($(this));
或者像这样声明:

(function ($) {
     $.fn.anotherfunc = function () {
           // some code
     }
})(jQuery);
$(this).anotherfunc();
然后你可以像这样使用它:

(function ($) {
     $.fn.anotherfunc = function () {
           // some code
     }
})(jQuery);
$(this).anotherfunc();

看看这个演示:

这是因为
$(this)
指的是
$(“.card”)。在('flip:done',function(){..}
查看javascript范围,并确认它是这样声明的。$.fn.anotherfunc=function(){//some code}感谢它是这样工作的。$.fn.anotherfunc=function(){//some code}很好。你应该选择并投票支持Ashkan的答案。