我只在主页上收到此错误。我该如何解决这个问题?
如果我访问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');
});
});
});
答案 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');
});
});
}
});