Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.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
Javascript Wordpress循环中的jQuery帮助_Javascript_Jquery_Wordpress_Wordpress Theming - Fatal编程技术网

Javascript Wordpress循环中的jQuery帮助

Javascript Wordpress循环中的jQuery帮助,javascript,jquery,wordpress,wordpress-theming,Javascript,Jquery,Wordpress,Wordpress Theming,我正在制作一个自定义的归档页面,它将显示文章的列表及其摘要,还有一个按钮,单击该按钮可以切换其余的文章内容。我让它处理这个代码,除了它切换每个帖子内容lol,因为在循环中他们都得到了类,你知道我的意思吗 你能帮我想个办法吗?一定有办法让它在循环中工作,对吗?这是我到目前为止的(失败)代码, 非常感谢。 ` $('.请参阅所有)。单击(函数(){ 如果($(this.html()=='More'){ $('.content_hidden')。切换('slow'); $(this.htm

我正在制作一个自定义的归档页面,它将显示文章的列表及其摘要,还有一个按钮,单击该按钮可以切换其余的文章内容。我让它处理这个代码,除了它切换每个帖子内容lol,因为在循环中他们都得到了类,你知道我的意思吗

你能帮我想个办法吗?一定有办法让它在循环中工作,对吗?这是我到目前为止的(失败)代码, 非常感谢。 `



$('.请参阅所有)。单击(函数(){
如果($(this.html()=='More'){
$('.content_hidden')。切换('slow');
$(this.html('Less');
}
else if($(this.html()=='Less'){
$('.content_hidden').slideUp('slow');
$(this.html('More');
}
返回false;
});
`使用

<?php the_ID(); ?> 

设置元素的HTML ID,然后使用Javascript选择要显示的容器ID。

应该可以:

$('.see_all').click(function() {
    if ( $(this).html() == 'More'){
        $(this).parent().find('.content_hidden').toggle('slow');
        $(this).html('Less');
    } else if ( $(this).html() == 'Less'){
        $(this).parent().find('.content_hidden').slideUp('slow');
        $(this).html('More');
    }        
    return false;
});
引用你的话:

它切换每个帖子内容lol 因为在循环中他们都得到了 你们知道我的意思吗


您需要做的是在单击链接的每个容器内或相对于每个容器的
.content hidden
,而不是同时寻址所有容器。此外,您可能在文档中重复ID(这是坏的、禁止的、禁忌的、不做的、无效的、违反规范的、不起作用的等等)。所以,你的
应该是

啊哈!谢谢,哈哈,我在那里的身份证上记下了,很好,谢谢。所以这是最有效的,例如有两个帖子。第二个按它应该的方式工作,但是第一个按一下它会向下滑动然后立即向上滑动……你知道为什么第一个div会在第二个div正常工作时向下滑动然后右向上滑动吗?
<?php the_ID(); ?> 
$('.see_all').click(function() {
    if ( $(this).html() == 'More'){
        $(this).parent().find('.content_hidden').toggle('slow');
        $(this).html('Less');
    } else if ( $(this).html() == 'Less'){
        $(this).parent().find('.content_hidden').slideUp('slow');
        $(this).html('More');
    }        
    return false;
});