Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

javascript - Javascript:设置location.href与location(Javascript: Setting location.href versus location)

When would you set location to a URL string versus setting location.href ?(您何时将location设置为URL字符串而不是setting location.href ?)

location = "http://www.stackoverflow.com"; vs(与) location.href = "http://www.stackoverflow.com"; Mozilla Developer Network Reference(Mozilla开发人员网络参考)   ask by chimerical translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You might set location directly because it's slightly shorter.(您可能会直接设置location ,因为它的location略短。)

If you're trying to be terse, you can usually omit the window.(如果您要简洁,通常可以省略window.) too.(太。) 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.(URL分配给location.hreflocation的定义都可以在JavaScript 1.0中使用,也可以在Netscape 2中使用,并且此后已在每个浏览器中实现。) So take your pick and use whichever you find clearest.(因此,请选择并使用最清晰的内容。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...