URL 索引为 1 和 10 和 11 相同

  • 本文关键字:相同 索引 URL jquery
  • 更新时间 :
  • 英文 :


我如何解决这个问题,索引网址以添加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")