jquery跳转到指定页面
使用 jQuery 跳转到指定页面
jQuery 可以通过修改 window.location 或触发链接点击来实现页面跳转。以下是几种常见方法:
方法一:直接修改 window.location.href

$(document).ready(function() {
window.location.href = "https://example.com/target-page.html";
});
方法二:使用 window.location.replace
此方法不会在浏览器历史记录中留下原页面记录:
$(document).ready(function() {
window.location.replace("https://example.com/target-page.html");
});
方法三:通过触发链接跳转
适用于页面中已存在链接元素的情况:

<a id="targetLink" href="https://example.com/target-page.html" style="display:none;"></a>
<script>
$(document).ready(function() {
$("#targetLink")[0].click();
});
</script>
方法四:延迟跳转
使用 setTimeout 实现延迟跳转(单位:毫秒):
$(document).ready(function() {
setTimeout(function() {
window.location.href = "https://example.com/target-page.html";
}, 3000); // 3秒后跳转
});
动态参数传递
若需携带参数跳转,可拼接 URL:
var userId = 123;
$(document).ready(function() {
window.location.href = "https://example.com/profile?id=" + userId;
});
注意事项
- 确保 URL 格式正确(包含
http://或https://协议头) - 跳转前可添加条件判断逻辑
- 使用
replace()方法时,用户无法通过浏览器后退按钮返回原页面






