本文介绍了Javascript:设置location.href与位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么时候将 location
设置为URL字符串而不是设置 location.href
?
When would you set location
to a URL string versus setting location.href
?
location = "http://www.stackoverflow.com";
vs
location.href = "http://www.stackoverflow.com";
推荐答案
您可能会设置 location
直接因为它略短。如果你想要简洁,你通常可以省略窗口。
。
You might set location
directly because it's slightly shorter. If you're trying to be terse, you can usually omit the window.
too.
两者的URL分配 location.href
和 location
被定义为在JavaScript 1.0中运行,返回Netscape 2,并且已在每个浏览器自此。因此,请选择并使用您认为最清楚的选项。
URL assignments to both location.href
and location
are defined to work in JavaScript 1.0, back in Netscape 2, and have been implemented in every browser since. So take your pick and use whichever you find clearest.
这篇关于Javascript:设置location.href与位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!