JavaScript 中带参数跳转页面的方法有三种:window.location.href、window.location.replace 和 window.open,分别用于创建新历史记录、替换当前历史记录和在新窗口或标签页中打开页面。目标页面可通过 window.location.search 获取传递的参数值。

JavaScript 带参数跳转页面
在 JavaScript 中,可以通过以下方式带参数跳转页面:
方法:
1. window.location.href
<code class="js">window.location.href = "newpage.html?param1=value1¶m2=value2";</code>
2. window.location.replace
<code class="js">window.location.replace("newpage.html?param1=value1¶m2=value2");</code>区别:
window.location.href 会创建一个新的历史记录,而 window.location.replace 则会替换当前历史记录。3. window.open
<code class="js">window.open("newpage.html?param1=value1¶m2=value2");</code>区别:
window.open 会在一个新窗口或标签页中打开页面。获取参数值:
在目标页面中,可以使用 window.location.search 获取传递的参数值:
<code class="js">const params = new URLSearchParams(window.location.search);
const param1 = params.get("param1");
const param2 = params.get("param2");</code>以上就是js如何带参数跳转页面跳转的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号