js获取url锚链,操作class和id的显示和隐藏
程序员文章站
2022-05-06 08:05:00
...
http://xxxx.com/admin/goods/add.html#desc
需要获取到后面的#desc,来让这个id为desc的div显示,其他某一个class隐藏
var thisId = window.location.hash;
console.log();//#desc
var thisId = window.location.hash;
thisId=thisId.substr(1,thisId.length-1);
console.log();//desc
var tpls=document.getElementsByClassName('tpls');
for (var i = 0; i<tpls.length;i++) {
tpls[i].style.display="none";
};
document.getElementById(thisId).style.display='block';
下一篇: winform 常见问题