我试图在用户关闭可扩展文本后让“减号”变回加号。
代码如下 HTML
<p class="textDropTitle"><span class="textDropLogo"></span>Title</p>
<div class="textDropSub"><p>This is my text Below</div>
<p class="textDropTitle"><span class="textDropLogo">+</span>Title</p>
<div class="textDropSub"><p>This is my text Below</div>
<p class="textDropTitle"><span class="textDropLogo">+</span>Title</p>
<div class="textDropSub"><p>This is my text Below</div>
jQuery
$(".textDropSub").hide();
$('.textDropLogo', this).text('+');
$(".textDropTitle").click(function() {
$(this).next().toggle('fast');
$('.textDropLogo', this).text('-');
});
最佳答案
使用条件三元运算符非常简单 (?:)
$(".textDropTitle").click(function() {
$(this).next().toggle('fast');
var $el = $('.textDropLogo', this);
$el.text( $el.text() == '+' ? '-' : '+' );
});
[condition] ? [if is true] : [if is false] ;
关于jQuery 改变点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14698598/