Are there any differenc开发者_如何学Pythones between window.location.hash
and $(window).location.hash
?
There are differences - jQuery will parse and preform a bunch of unnecessary operations on the object, so just doing window.location.hash
is better.
Wrapping things like this
or window
inside a call to $
is only useful when you want to use a jQuery method on the resulting object, since a call to $
will return the object wrapped inside a jQuery object. So, in this case, just use window.location.hash
Well, one works, the other doesn't.
Doing $(window)
will wrap the window
object inside a jQuery
object, and the jQuery
object doesn't have a location
property, so you will get undefined
back. As you can't get the property hash
(or any property) from undefined
, the code ends with the error message "$(window).location is undefined"
.
精彩评论