簡體   English   中英

window.location.hash和$(window).location.hash之間的區別

[英]Differences between window.location.hash and $(window).location.hash

window.location.hash$(window).location.hash之間有什么區別嗎?

僅在您要在生成的對象上使用jQuery方法時,將thiswindow包裝在$調用中才有用,因為對$的調用將返回包裝在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM