gpt4 book ai didi

javascript - 为什么js函数在另一个函数内部工作但不能单独工作

转载 作者:行者123 更新时间:2023-11-28 13:47:56 24 4
gpt4 key购买 nike

我有下面这两个函数,无论出于何种原因,windowedBox 函数仅在我从另一个函数调用它时才起作用。如果我直接调用 windowedBox(),它不会执行任何操作。如果我调用 getShareButtons(),它会调用 windowedBox() 并正常工作。如果有人知道为什么会发生这种情况,请帮助我。 :(

注意::如果您想知道为什么它显示 $j 而不是 $,因为我就是这样设置的。

function getShareButtons(){
var postPath = window.location.pathname;
var videoTitle = 'asdf';
var videoURL = 'asdf';

//Output social button attributes
$j(".facebook-share").attr('href', 'asdf');
windowedBox(); <---THIS CALL WORKS
}

function windowedBox() {
$j(".facebook-share, .twitter-share").click(function(){
window.open(this.href, videoTitle, "width=626, height=436", "status=0", "toolbar=0");
return false;
});
}

最佳答案

我猜这是因为你正在使用变量

videoTitle 

它不是在此函数中声明的,而是在另一个函数中声明的:)

关于javascript - 为什么js函数在另一个函数内部工作但不能单独工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12878313/

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