Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在单击时切换div中的字符_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在单击时切换div中的字符

Javascript 在单击时切换div中的字符,javascript,jquery,html,Javascript,Jquery,Html,当单击.articletTitle时,我希望下面的代码能够在向上和向下箭头之间切换.articleArrow的html内容: jQuery $(".articleTitle").click(function () { if ($(this).children('.articleArrow').html() == '↑') $(this).children('.articleArrow').html('↓'); else if

当单击
.articletTitle
时,我希望下面的代码能够在向上和向下箭头之间切换
.articleArrow
的html内容:

jQuery

$(".articleTitle").click(function () {
    if ($(this).children('.articleArrow').html() == '↑')
        $(this).children('.articleArrow').html('↓');
    else if ($(this).children('.articleArrow').html() == '↓')
        $(this).children('.articleArrow').html('↑');
});
HTML

<div class='articleTitle'>
    Blah
    <div class='articleArrow'>
        &#8595;
    </div>
</div>

废话
↓
但它什么也没用。另一方面,如果我取出
if…else if
并将字符设置为
$(this).children('.articleArrow').html('↑;')它可以工作。因此,设置角色是有效的,如果没有正确触发,则是
if…else
,我不知道为什么


(不要激动,这不是实际的管理面板!)

如果我使用unicode字符来比较:

$(".articleTitle").click(function () {
    if ($(this).children('.articleArrow').html() == '↓') $(this).children('.articleArrow').html('&#8593;');
    else if ($(this).children('.articleArrow').html() == '↑') $(this).children('.articleArrow').html('&#8595;');
});

如果我使用unicode字符来比较:

$(".articleTitle").click(function () {
    if ($(this).children('.articleArrow').html() == '↓') $(this).children('.articleArrow').html('&#8593;');
    else if ($(this).children('.articleArrow').html() == '↑') $(this).children('.articleArrow').html('&#8595;');
});

如果我使用unicode字符来比较:

$(".articleTitle").click(function () {
    if ($(this).children('.articleArrow').html() == '↓') $(this).children('.articleArrow').html('&#8593;');
    else if ($(this).children('.articleArrow').html() == '↑') $(this).children('.articleArrow').html('&#8595;');
});

如果我使用unicode字符来比较:

$(".articleTitle").click(function () {
    if ($(this).children('.articleArrow').html() == '↓') $(this).children('.articleArrow').html('&#8593;');
    else if ($(this).children('.articleArrow').html() == '↑') $(this).children('.articleArrow').html('&#8595;');
});

只需使用's和jQuery的选择器,您就可以轻松地完成此操作,而无需使用凌乱的
if语句

$(".articleTitle").click(function () {
    //  1st, i go ahead and asign our arrow element to a variable for use in callback
    var arrow = $(this).find('.articleArrow');
    $(this).siblings('.articleContent').slideToggle("slow", function(){
        //  this is the `complete` callback method
        //  in here, we can now manipulate whatever we need to when the "toggle" is `complete`
        arrow.html( $(this).is(':visible') ? '&#8593;' : '&#8595;' );
        //  inside the .html statement is a simple `inline if` statement that simply says:
        //      if true ? do this : else do this
    });
});


普通代码:

$(".articleTitle").click(function () {
    var a = $(this).find(".articleArrow");
    $(this).siblings(".articleContent").slideToggle("slow", function () {
        a.html($(this).is(":visible") ? "&#8593;" : "&#8595;")
    })
});

只需使用's和jQuery的选择器,就可以轻松地完成此操作,而无需使用凌乱的
if语句

$(".articleTitle").click(function () {
    //  1st, i go ahead and asign our arrow element to a variable for use in callback
    var arrow = $(this).find('.articleArrow');
    $(this).siblings('.articleContent').slideToggle("slow", function(){
        //  this is the `complete` callback method
        //  in here, we can now manipulate whatever we need to when the "toggle" is `complete`
        arrow.html( $(this).is(':visible') ? '&#8593;' : '&#8595;' );
        //  inside the .html statement is a simple `inline if` statement that simply says:
        //      if true ? do this : else do this
    });
});


普通代码:

$(".articleTitle").click(function () {
    var a = $(this).find(".articleArrow");
    $(this).siblings(".articleContent").slideToggle("slow", function () {
        a.html($(this).is(":visible") ? "&#8593;" : "&#8595;")
    })
});

只需使用's和jQuery的选择器,就可以轻松地完成此操作,而无需使用凌乱的
if语句

$(".articleTitle").click(function () {
    //  1st, i go ahead and asign our arrow element to a variable for use in callback
    var arrow = $(this).find('.articleArrow');
    $(this).siblings('.articleContent').slideToggle("slow", function(){
        //  this is the `complete` callback method
        //  in here, we can now manipulate whatever we need to when the "toggle" is `complete`
        arrow.html( $(this).is(':visible') ? '&#8593;' : '&#8595;' );
        //  inside the .html statement is a simple `inline if` statement that simply says:
        //      if true ? do this : else do this
    });
});


普通代码:

$(".articleTitle").click(function () {
    var a = $(this).find(".articleArrow");
    $(this).siblings(".articleContent").slideToggle("slow", function () {
        a.html($(this).is(":visible") ? "&#8593;" : "&#8595;")
    })
});

只需使用's和jQuery的选择器,就可以轻松地完成此操作,而无需使用凌乱的
if语句

$(".articleTitle").click(function () {
    //  1st, i go ahead and asign our arrow element to a variable for use in callback
    var arrow = $(this).find('.articleArrow');
    $(this).siblings('.articleContent').slideToggle("slow", function(){
        //  this is the `complete` callback method
        //  in here, we can now manipulate whatever we need to when the "toggle" is `complete`
        arrow.html( $(this).is(':visible') ? '&#8593;' : '&#8595;' );
        //  inside the .html statement is a simple `inline if` statement that simply says:
        //      if true ? do this : else do this
    });
});


普通代码:

$(".articleTitle").click(function () {
    var a = $(this).find(".articleArrow");
    $(this).siblings(".articleContent").slideToggle("slow", function () {
        a.html($(this).is(":visible") ? "&#8593;" : "&#8595;")
    })
});


你想让箭头字符在按下时切换吗?(向上箭头和向下箭头)@Austin是的,我希望它在单击父div时在向上和向下之间切换。一旦HTML实体插入DOM中,实体将被解析,不再是实体,因此
HTML()
不会返回实体,你可以通过将你的值记录到控制台来计算出来。那么你想让箭头字符在按下时切换吗?(向上箭头和向下箭头)@Austin是的,我希望它在单击父div时在向上和向下之间切换。一旦HTML实体插入DOM中,实体将被解析,不再是实体,因此
HTML()
不会返回实体,你可以通过将你的值记录到控制台来计算出来。那么你想让箭头字符在按下时切换吗?(向上箭头和向下箭头)@Austin是的,我希望它在单击父div时在向上和向下之间切换。一旦HTML实体插入DOM中,实体将被解析,不再是实体,因此
HTML()
不会返回实体,你可以通过将你的值记录到控制台来计算出来。那么你想让箭头字符在按下时切换吗?(向上箭头和向下箭头)@Austin是的,我希望它在单击父div时在向上和向下之间切换。一旦HTML实体插入DOM中,实体将被解析,不再是实体,因此
HTML()
不会返回实体,您可以通过将您的值记录到控制台来了解这一点。感谢您了解了一些新内容!我是jQuery新手,但如果我理解正确,那么对“:visible”的检查只会返回true(当然,如果它是可见的)。但我可以用“真”来代替它,或者其他任何返回真的东西?可见检查在这里没有其他用途不?@有趣的是,可见检查在这里用于决定元素是打开还是关闭。如果它已关闭,则不可见。你可以用任何东西来代替它,但我不确定还有什么东西能满足你在这里想要实现的目标?谢谢,我学到了一些新东西!我是jQuery新手,但如果我理解正确,那么对“:visible”的检查只会返回true(当然,如果它是可见的)。但我可以用“真”来代替它,或者其他任何返回真的东西?可见检查在这里没有其他用途不?@有趣的是,可见检查在这里用于决定元素是打开还是关闭。如果它已关闭,则不可见。你可以用任何东西来代替它,但我不确定还有什么东西能满足你在这里想要实现的目标?谢谢,我学到了一些新东西!我是jQuery新手,但如果我理解正确,那么对“:visible”的检查只会返回true(当然,如果它是可见的)。但我可以用“真”来代替它,或者其他任何返回真的东西?可见检查在这里没有其他用途不?@有趣的是,可见检查在这里用于决定元素是打开还是关闭。如果它已关闭,则不可见。你可以用任何东西来代替它,但我不确定还有什么东西能满足你在这里想要实现的目标?谢谢,我学到了一些新东西!我是jQuery新手,但如果我理解正确,那么对“:visible”的检查只会返回true(当然,如果它是可见的)。但我可以用“真”来代替它,或者其他任何返回真的东西?可见检查在这里没有其他用途不?@有趣的是,可见检查在这里用于决定元素是打开还是关闭。如果它已关闭,则不可见。你可以用任何东西来代替它,但我不确定还有什么东西能满足你在这里想要实现的目标?