Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.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

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 选中下拉项中页面加载时的活动勾号_Javascript_Jquery_Html_Css_.net - Fatal编程技术网

Javascript 选中下拉项中页面加载时的活动勾号

Javascript 选中下拉项中页面加载时的活动勾号,javascript,jquery,html,css,.net,Javascript,Jquery,Html,Css,.net,我已经编写了一个JavaScript,在所选下拉项的右侧显示一个勾号(CSS类名active): 它工作得很好,但我这里有个问题 问题: 刷新页面时,下拉列表将默认为默认的选定项。但所选项目未显示勾号 如何重写查询以在下拉列表中显示默认选定项的勾号?您需要在li上循环,以便各个链接负责自己的事件 $(document).ready(function () { $('.select-country ul li a.default').addClass("active"); //l

我已经编写了一个JavaScript,在所选下拉项的右侧显示一个勾号(CSS类名
active
):

它工作得很好,但我这里有个问题

问题:

刷新页面时,下拉列表将默认为默认的选定项。但所选项目未显示勾号


如何重写查询以在下拉列表中显示默认选定项的勾号?

您需要在
li
上循环
,以便各个链接负责自己的事件

$(document).ready(function () {

    $('.select-country ul li a.default').addClass("active");
    //loop over all li
    $('.select-country ul li a').each(function () {
        //remove first from any active link
        $(this).click(function(){
            $('.select-country ul li a').removeClass("active");
           //find and add active on "this" link
           $(this).addClass("active");

           return false; 
        });

    });
});

你能为它创建JSFIDLE吗?
$(document).ready(function () {

    $('.select-country ul li a.default').addClass("active");
    //loop over all li
    $('.select-country ul li a').each(function () {
        //remove first from any active link
        $(this).click(function(){
            $('.select-country ul li a').removeClass("active");
           //find and add active on "this" link
           $(this).addClass("active");

           return false; 
        });

    });
});