在JavaScript中,location.href是一个属性,用于获取或设置当前页面的URL。它有以下用法:
var url = location.href;
console.log(url);
location.href = "http://example.com";
location.href = "/path/to/page.html";
location.href = "#section1";
location.href = "?key=value";
location.href = "#section1?key=value";
location.href = "http://example.com";
请注意,使用location.href设置URL会导致页面的重加载。