gpt4 book ai didi

javascript - 在 jQuery 链中调用 JavaScript 函数

转载 作者:行者123 更新时间:2023-11-28 14:03:06 25 4
gpt4 key购买 nike

function jsFunc() {
alert('i am js!');
}

$('#node').slideDown().call(jsFunc());

当然,该函数不称为“call”。

** 编辑 **

(代表OP添加解决方案)

解决方案

http://jsfiddle.net/gx2mJ/1/

HTML:

<div id="content">
<p class="article">
this is an article
</p>
</div>

JavaScript:

function callBack() {
$("#content .article").html("the callback has been called");
}

$(document).ready(function() {
$("#content .article").slideUp(0);

$("#content .article").each(function(i) {
$(this).delay(i*250).slideDown(function(){
//if ($("#content .article:animated").length < 1) {
callBack();
//}
});
});
});

最佳答案

默认情况下您不能这样做,但您可以轻松地将其添加为插件:

$.fn.call = function (fn, args, thisp) {
fn.apply(thisp || this, args);
return this; // if you want to maintain chainability -- other wise, you can move the return up one line..
}

虽然我不确定你为什么要这样做。如果您认为它要等到slide 完成后才会运行,那么您就错了,因为 jQuery 动画是异步的。

关于javascript - 在 jQuery 链中调用 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3903328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com