在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会导致页面的重加载。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>