我下面有这两个函数,无论出于什么原因,windowedBox函数只有在我从另一个函数调用它时才起作用。如果我直接调用windowedBox(),它不会做任何事情。如果我调用getShareButtons(),它就会调用windowedBox()并正常工作。如果有人知道为什么会这样,请帮帮我。:(
注意:如果您想知道为什么它显示为$j而不是$ its,因为我是这样设置的。
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;
});
}发布于 2012-10-14 08:45:07
我猜这是因为您使用了变量
videoTitle 它没有在这个函数中声明,而是在另一个函数中声明:)
发布于 2012-10-14 08:42:53
您会得到一个错误,因为在第一个函数中设置了链接href属性,但是如果只调用第二个函数,则this.href保持未定义或为空
像这样试一下
$j(".facebook-share").attr('href', 'asdf');
var videoTitle = 'Title';
windowedBox();
function windowedBox() {
$j(".facebook-share, .twitter-share").click(function(){
window.open(this.href, videoTitle, "width=626, height=436", "status=0", "toolbar=0");
return false;
});
}https://stackoverflow.com/questions/12878313
复制相似问题