0

I have ,

jQuery(function ($) {
    var allArrows = $(".arrow"),
        arrowUpUrl = "select_arrow_up.png",
        arrowDownUrl = "select_arrow.png";

    allArrows.click(function () {
        var currentUrl = $(this).attr("src");

        $(this).attr("src", currentUrl === arrowDownUrl ? arrowUpUrl : arrowDownUrl);

        allArrows.not(this).attr("src", arrowDownUrl);
    });
});

my problem is when I click outside arrow do not return first position what I must change ?

i can't use css and toggle whit jquery I need to use images with outside place

http://jsfiddle.net/cYCnD/9/

4

2 回答 2

0

如果我理解正确,您希望在用户单击页面上的其他位置时重置箭头位置。

如果是这样,我相信这会奏效:

 $(document).click(function(e){
    if(!$(e.target).hasClass('arrow'))
         $(".arrow").attr("src", select_arrow.png)
 });
于 2013-10-15T18:14:39.853 回答
0

您应该添加以下处理程序:

$(document).on('click', function(e) {
    if (!$(e.target).hasClass('arrow')) {
        $('.arrow').attr('src', 'select_arrow.png');
    }
});

看我的小提琴:http: //jsfiddle.net/cYCnD/10/

整个代码应如下所示:

jQuery(function ($) {
    var allArrows = $(".arrow"),
    arrowUpUrl = "select_arrow_up.png",
    arrowDownUrl = "select_arrow.png";

    allArrows.click(function () {
        var currentUrl = $(this).attr("src");

        $(this).attr("src", currentUrl === arrowDownUrl ? arrowUpUrl : arrowDownUrl);

        allArrows.not(this).attr("src", arrowDownUrl);
    });

    $(document).on('click', function(e) {
        if (!$(e.target).hasClass('arrow')) {
            allArrows.attr('src', 'select_arrow.png');
        }
    });
});
于 2013-10-16T08:06:19.473 回答