您可以使用以下 JavaScript 代码来实现根据 type 跳转到不同页面,并携带前面的参数:/n/njavascript/n// 获取URL参数/nfunction getUrlParameter(name) {/n name = name.replace(/[/[]/, '//[').replace(/[/]]/, '//]');/n var regex = new RegExp('[//?&]' + name + '=([^&#]*)');/n var results = regex.exec(location.search);/n return results === null ? '' : decodeURIComponent(results[1].replace(//+/g, ' '));/n};/n/n// 获取type参数的值/nvar type = getUrlParameter('type');/n/n// 获取前面的参数/nvar parameters = window.location.href.split('&')[0].split('?')[1];/n/n// 拼接参数/nvar url = '';/n/nif (type === 'recovery') {/n url = 'recovery.html?' + parameters;/n} else if (type === 'something_else') {/n url = 'something_else.html?' + parameters;/n} else {/n url = 'default.html';/n}/n/n// 跳转到不同页面/nwindow.location.href = url;/n/n/n上述代码中,首先定义了一个getUrlParameter函数,用于获取URL中的参数。然后使用该函数获取 type 参数的值,并获取前面的参数。接着根据 type 的不同值拼接不同的 URL,最后通过window.location.href跳转到相应的页面。如果 type 不匹配任何条件,则跳转到默认页面default.html

JavaScript 根据 URL 参数 type 跳转页面并携带参数

原文地址: https://www.cveoy.top/t/topic/qDCM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录