Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有什么方法可以判断是否window.location.hash已定义?
window.location.hash
如果已设置,那么我将获取变量的值,并使用它在页面上显示额外的内容。
if(window.location.hash) { // do stuff! }
怎么样:
if(window.location.hash !== '') { }
或者
if(typeof window.location.hash !== 'undefined') { //your code }