![](/img/trans.png)
[英]location.hash = window.location.hash does not work in Chrome
[英]Differences between window.location.hash and $(window).location.hash
window.location.hash
和$(window).location.hash
之間有什么區別嗎?
僅在您要在生成的對象上使用jQuery方法時,將this
或window
包裝在$
調用中才有用,因為對$
的調用將返回包裝在jQuery對象中的對象。 因此,在這種情況下,只需使用window.location.hash
兩者之間存在差異-jQuery將解析並對對象執行一堆不必要的操作,因此僅執行window.location.hash
更好。
好吧,一個可行,另一個不可行。
$(window)
會將window
對象包裝在jQuery
對象中,並且jQuery
對象沒有location
屬性,因此您將獲得undefined
返回值。 由於無法從undefined
獲取屬性hash
(或任何屬性),因此代碼以錯誤消息"$(window).location is undefined"
結尾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.