未捕获错误:语法错误,无法识别的表达式:/

时间:2017-05-28 07:16:11

标签: jquery

我只在主页上收到此错误。我该如何解决这个问题?
如果我访问example.com但访问example.com/index.html

时效果很好
    $(document).ready(function() {
    var url =
        window.location.href;
    var start = url.substr(url.indexOf("#"));
    $(start).collapse('show');
    $('.collapse.in').prev('.panel-heading').addClass('active');
    $("#accordion, #bs-collapse").on("show.bs.collapse", function(a) {
        $(a.target).prev('.panel-heading').addClass('active');
        var curr =
            $(a.target).attr("id");
        var url = window.location.href;
        var start = window.location.hash;
        if (start.length > 0) {
            window.location.href = url.replace(start, "#" + curr);
        } else {
            window.location.href = url + "#" + curr;
        }
        $("#accordion, #bs-collapse").on('hide.bs.collapse',
            function(a) {
                $(a.target).prev('.panel-heading').removeClass('active');
            });
    });
});

1 个答案:

答案 0 :(得分:1)

尝试以下代码

您只需在payment.html页面中使用这些代码。但是每次调用它都会导致错误

    $(document).ready(function() {
    if ($(".panel-group").length > 0) {
        var url = window.location.href;
        var start = url.substr(url.indexOf("#"));
        $(start).collapse('show');
        $('.collapse.in').prev('.panel-heading').addClass('active');
        $("#accordion, #bs-collapse").on("show.bs.collapse", function(a) {
            $(a.target).prev('.panel-heading').addClass('active');
            var curr =
                $(a.target).attr("id");
            var url = window.location.href;
            var start = window.location.hash;
            if (start.length > 0) {
                window.location.href = url.replace(start, "#" + curr);
            } else {
                window.location.href = url + "#" + curr;
            }
            $("#accordion, #bs-collapse").on('hide.bs.collapse',
                function(a) {
                    $(a.target).prev('.panel-heading').removeClass('active');
                });
        });
    }
});