<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>
单击第一次后,“显示所有新闻”文本将变为“关闭”。现在我需要一种方法将其从“关闭”更改为“显示所有新闻”等等......
祝你好运!
答案 0 :(得分: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>
答案 1 :(得分: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')
})
不是最好的方法,但这可以做到。
答案 2 :(得分:0)
试试这个
<script>
...
$("#showallnews").toggle(function (){
$("#showallnews").text("SHOW ALL NEWS")
.stop();
}, function(){
$("#showallnews").text("CLOSE")
.stop();
});
</script>