Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图做一个按钮,在你按下之前显示更多,然后在你按下时隐藏。问题是,当您按下隐藏时,它不会变回查看更多。我该如何解决这个问题?
jQuery代码是:
$("#single .vm").click(function () { $("#singlemore").slideToggle(150); $("#single .vm").html('Hide'); });
View more您可以使用三元运算符在文本和之间切换,Hide并使用$(this)而不是 $("#single .vm")
View more
Hide
$(this)
$("#single .vm").click(function () { $("#singlemore").slideToggle(150); $(this).html($(this).html() == 'Hide' ? 'View more' : 'Hide'); });