我如何解决这个问题,索引网址以添加css。
当我转到 #10 或 #11 的网址索引时,它正在将 css 应用于 #1 的网址索引,我如何匹配 #1 节 #10 和 #11 ?
if ( document.location.href.indexOf('#1') > -1 ) {
$('#tabcontent1').css('display','block');
}
if ( document.location.href.indexOf('#10') > -1 ) {
$('#tabcontent10').css('display','block');
}
if ( document.location.href.indexOf('#11') > -1 ) {
$('#tabcontent11').css('display','block');
}
使用 document.location.hash
var curr = document.location.hash.slice(1);
$("#tabcontent" + curr).css("display", "block")