Layui 跳转页面传递参数的步骤:设置跳转目标地址,拼接查询字符串(?开头,参数用&分隔)。目标页面接收参数:获取查询字符串,解析参数。

Layui 跳转页面并传递参数
如何实现?
使用 Layui 框架跳转页面时,可以通过以下步骤传递参数:
location.href 方法设置跳转目标页面的地址。location.href = 'index.html?id=1&name=John'。window.location.search 获取查询字符串,并使用 URLSearchParams 对象解析参数。例如:<code class="javascript">const params = new URLSearchParams(window.location.search);
const id = params.get('id');
const name = params.get('name');</code>示例代码
<code class="html"><!-- 源页面 -->
<a class="layui-btn" onclick="jump();">跳转到目标页面</a>
<script>
function jump() {
location.href = 'index.html?id=1&name=John';
}
</script>
<!-- 目标页面 -->
<script>
const params = new URLSearchParams(window.location.search);
const id = params.get('id');
const name = params.get('name');
console.log('接收到的参数:', id, name);
</script></code>注意点
以上就是Layui 跳转页面并传递参数的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号