Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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
Jquery 。在循环中单击()_Jquery_Ajax_Facebook_Wordpress - Fatal编程技术网

Jquery 。在循环中单击()

Jquery 。在循环中单击(),jquery,ajax,facebook,wordpress,Jquery,Ajax,Facebook,Wordpress,我的wordpress帖子循环中有以下内容: function newWindow(uri,width,height) { if(!window.open(uri,uri,'scrollbars=1,toolbar=0,resizable=1,status=0,width='+width+',height='+height)) { document.location.href=uri; } } $('.facebook_button').click(functio

我的wordpress帖子循环中有以下内容:

function newWindow(uri,width,height) {
    if(!window.open(uri,uri,'scrollbars=1,toolbar=0,resizable=1,status=0,width='+width+',height='+height)) {
        document.location.href=uri;
    }
}
$('.facebook_button').click(function() {
    newWindow('http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>',720,420);
    return false; 
});
函数新建窗口(uri、宽度、高度){
如果(!window.open(uri,uri,'scrollbars=1,toolbar=0,resizable=1,status=0,width='+width+',height='+height)){
document.location.href=uri;
}
}
$('.facebook_按钮')。单击(函数(){
新窗口('http://www.facebook.com/sharer.php?u=',720,420);
返回false;
});
因此,当我点击按钮时,它会打开几个窗口(10个用于索引页面上的10篇文章)。有没有办法只打开按钮所在的post


谢谢

循环中不应该有javascript函数定义(只需要输出一次)

我建议为循环中的每个项添加一个唯一的id(可能是
的\u permalink()
值的散列),这样您就可以很好地处理选择器。因此,您可以在循环中输出如下内容

$('#<?php echo md5(get_permalink()); ?>').click(function() {
    newWindow('http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>',720,420);
    return false; 
});
$('#')。单击(函数(){
新窗口('http://www.facebook.com/sharer.php?u=',720,420);
返回false;
});

当然,您还必须将
id=”“
添加到您输出的按钮。

您不应该在循环中包含javascript函数定义(它只需要输出一次)

我建议为循环中的每个项添加一个唯一的id(可能是
的\u permalink()
值的散列),这样您就可以很好地处理选择器。因此,您可以在循环中输出如下内容

$('#<?php echo md5(get_permalink()); ?>').click(function() {
    newWindow('http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>',720,420);
    return false; 
});
$('#')。单击(函数(){
新窗口('http://www.facebook.com/sharer.php?u=',720,420);
返回false;
});
当然,您还必须将
id=”“
添加到您输出的按钮。

$('facebook\u button')
也可以使用。
$('facebook\u button')
也可以使用。