jQuery 改变点击

标签 jquery html

我试图在用户关闭可扩展文本后让“减号”变回加号。

代码如下 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] ;

READ MORE

关于jQuery 改变点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14698598/

相关文章:

jquery - 使用jQuery获取src ="x"值

javascript - 可拖动框的小故障

jquery - Ajax.BeginForm 在 chrome MVC 5 中不起作用

javascript - 如何使用 javascript 'addEventlistner(' click')' 函数长时间更改 css 样式?

javascript - AJAX html stub ——加载清除的 head 元素是否实用?

javascript - 当使用多个选择器时,如何使用此关键字选择每个选择器?

javascript - 如何为 ngFor 循环添加条件

javascript - 如何使用 javascript 根据条件为 html 标记 (<span>) 添加类

查询 :Automatically change the width equal to an element

html - 在 WordPress Astra 主题上添加指向 HTML 按钮的链接