jquery - 如何重定向到另一个页面并在该页面上触发事件
问题描述
单击此按钮时,我创建了一个带有 id="work" 的按钮我试图重定向到联系我们页面,并且在联系我们页面中单击了带有 id="working-us" 的按钮。
jQuery
$("#work").click(function() {
window.location.replace("contactus.html");
sessionStorage.setItem("workWithUS", "true");
if (sessionStorage.workWithUs == "true") {
$("#working-us").trigger(click);
sessionStorage.removeItem("workWithUs");
});
HTML
<a href="javascript:void(0);" id="work">Join our Team</a><button class="topic-btn d-flex" data-toggle="tab" href="#working-us" id="work2">
解决方案
您的代码看起来不错,但缺少一个右括号,这可能会阻止 if 语句触发:
$("#work").click(function() {
window.location.replace("contactus.html");
sessionStorage.setItem("workWithUS", "true");
if (sessionStorage.workWithUs == "true") {
$("#working-us").trigger(click);
sessionStorage.removeItem("workWithUs");
}
});
推荐阅读
- spring-boot - 在 jhipster 服务器上管理数据库内容
- node.js - 预检请求 CORS 不允许重定向 url
- reactjs - TypeError:这在我的引导代码中未定义
- reactjs - Redux action.type 未定义
- mysql - 如何将数据从 AWS RDS PostgreSQL 数据库实例传输到不同服务器上的 mysql 数据库?
- memory-management - 递归可变二叉树:`已经借用:BorrowMutError`
- django-rest-framework - DRF 'ObtainAuthToken' 对象没有属性 'request'
- css - Safari 使用 flexbox 居中时不显示 SVG
- javascript - 将 createdAt 值从 sql 转换为相对时间(天、小时、分钟和秒)
- datastage - 如何在单独的文件中捕获 Null 值(custname)和相应的 CustID,在其他文件中捕获其余的 CustID