首页 > 解决方案 > 点击事件触发和页面加载后如何运行代码

问题描述

我正在开发一个通过 jquery 触发点击事件的 Web 应用程序。我在变量中还有一个链接 ID,例如“unit30”。所以当点击事件被触发时,新页面被加载。所以我必须在页面上找到该 id 并将类“活动”添加到它。我现在所做的是这个

jQuery(document).on('click','.course_lesson a',function(e){
e.preventDefault();
var href = $(this).attr('href');
var link = href.split("?")[1];
var unit = link.split("=")[1]; // this gives me id unit30
jQuery("input.course_button").trigger("click"); //click event is triggered and new page is loaded. now I have to find unit30 id on this page and add class "active" to it.
});

标签: jquerytriggersclick

解决方案


推荐阅读