0
<div id="sidebar_archive_infoline_bottom"><a id="showallnews" href="#">SHOW ALL NEWS</a></div>     

<script>
$('#newsdiv').hide();
$('#showallnews').click(function () {
$('#newsdiv').slideToggle('fast');
$('#showallnews').text('CLOSE')
}); </script>

第一次单击后,文本“显示所有新闻”变为“关闭”。现在我需要一种方法将其从“关闭”更改为“显示所有新闻”等等......

此致!

4

3 回答 3

2
<script>
    $('#newsdiv').hide();
    $('#showallnews').click(function() {
    $('#newsdiv').slideToggle('fast', function() {
        $('#showallnews').text().toLowerCase().indexOf('close') != -1 ? $('#showallnews').text('SHOW ALL NEWS') : $('#showallnews').text('CLOSE');
    });
});​
</script> 

演示

于 2012-05-23T12:52:54.377 回答
0
$('#showallnews').click(function () {
$('#newsdiv').slideToggle('fast');
$('#showallnews').addClass("closed");
$('#showallnews').text('CLOSE')
});

$('.closed').click(function(){
$('#newsdiv').slideToggle('fast');
$('#showallnews').removeClass("closed");
$('#showallnews').text('Show all news')

})

不是最好的方法,但这可以做到。

于 2012-05-23T12:51:56.967 回答
0

尝试这个

<script>
...
 $("#showallnews").toggle(function (){
            $("#showallnews").text("SHOW ALL NEWS")
            .stop();
        }, function(){

            $("#showallnews").text("CLOSE")
            .stop();
        });
</script>
于 2012-05-23T13:08:04.280 回答