jquery点击跳转
使用 jQuery 实现点击跳转
通过 jQuery 实现点击跳转功能,可以绑定点击事件并执行跳转逻辑。以下是几种常见实现方式:
绑定点击事件跳转
$('#elementId').click(function() {
window.location.href = 'https://example.com';
});
动态跳转带参数

$('.link-class').on('click', function() {
var page = $(this).data('page');
window.location.href = '/path/' + page;
});
新标签页打开链接
$('a.external-link').click(function(e) {
e.preventDefault();
window.open($(this).attr('href'));
});
表单提交后跳转

$('#submit-form').submit(function(e) {
e.preventDefault();
// 表单处理逻辑
window.location.href = '/success-page';
});
延时跳转
$('#delay-link').click(function() {
setTimeout(function() {
window.location.href = '/target-page';
}, 2000);
});
注意事项:
- 确保 DOM 加载完成后再绑定事件,通常将代码放在
$(document).ready()中 - 使用
preventDefault()可以阻止默认行为 - 对于动态生成的元素,使用事件委托
$(document).on('click', selector, handler)






