jQuery在函数中调用用户定义的函数
jQuery Calling user defined function within function
我试图在jquery函数中调用用户定义的函数,但没有成功。我已经尝试过:
function close_quote_bar() {
alert('oh hai');
}
if($('#sliding_quote:visible')) {
$('#sliding_quote').slideUp();
$('#trans_div').animate({opacity: 0.0}).css('display','none').close_quote_bar;
}
和这个
//Function to close quote bar
function close_quote_bar() {
alert('oh hai');
}
$('#get_quote_bar img').click(function() {
if($('#sliding_quote:visible')) {
$('#sliding_quote').slideUp();
$('#trans_div').animate({opacity: 0.0}).css('display','none').close_quote_bar;
}
});
运气不好!当我调用close_quote_bar,或者我得到一个Object is missing方法错误时,什么都不会发生!
希望你们能给我指明正确的方向,我真的很难适应这个
我想你想要这样的东西:
$('#sliding_quote:visible').slideUp( function(){
$('#trans_div').css('display','none');
close_quote_bar();
} );
它使用向上滑动回调,然后将对象设置为不显示,并运行您的函数。这段代码还取消了if语句,而是使用选择器只影响可见元素。
你应该试试这个:
$('#trans_div').animate({opacity: 0.0}, 400, function(){
$(this).css('display','none');
close_quote_bar();
});
基于@laurencek的答案。
$('#sliding_quote:visible').slideUp( function(){
$('#trans_div').fadeOut( function(){
close_quote_bar();
});
});
则执行作为CCD_ 2的回调的CCD_。
这行代码需要更改
$('#trans_div').animate({opacity: 0.0}).css('display','none').close_quote_bar;
你必须这样称呼它
$('#trans_div').animate({opacity: 0.0}).css('display','none');
close_quote_bar();
最后,在动画完成后触发closequotebar,使用此代码,注意第三个参数中有一个函数()。
$('#trans_div').animate({opacity: 0.0}, 400, function(){
$(this).css('display','none');
close_quote_bar();
});
animate和slideUp都支持添加function()块作为参数,因此可以在动画完成后调用函数http://api.jquery.com/animate/请参阅"完整"部分
事实证明,函数被调用了,这与范围或类似的问题无关。
我有另一个在scroll(.woll)上执行的函数,它与该函数冲突,因此它的行为出乎意料,似乎没有执行。
相关文章:
- 用嵌套函数和默认函数定义函数
- 使用Extjs进行函数定义
- JS中奇怪的函数定义语法
- 重写javascript函数定义
- 使用角度图时,我可以用函数定义数据点颜色吗
- modal.js中的匿名函数定义
- 为从AJAX调用中utlizes DATA参数的函数定义回调
- Emacs:在 etag 中查找函数定义
- Javascript:对象函数定义
- 为什么要在函数定义之外引用静态变量(函数属性)
- Ember 对象函数定义中的计算属性.js
- javascript/jQuery中函数定义的区别
- CoffeeScript 承诺与函数定义链接
- 如何在使用 eval() 评估 JavaScript 时将回调函数定义作为参数传递
- Javascript - 为什么下面的函数定义错误
- 使用函数声明时的自定义函数(也称为惰性函数定义)
- JavaScript 函数定义不正确
- jQuery off on 时是用匿名函数定义的
- 停止 IntelliJ 11 在启用 JSLint 时向每个嵌套函数定义添加“use strict”
- 为什么不是't我为这个函数定义的javascript函数