jQuery 函数正在为模态点击返回更多事件
我有一个网站,其中有三个不同的模式按钮,我编写了一个变量来获取数据层中的值,该值运行良好,但是当我第一次单击该按钮时,我收到 2 个事件,之后每次单击它都会开始加倍。
这是我的代码
function() {
if ({{Click Text}} == 'STUDY DESIGN'){
$(this).each(function() {
$(this).on("click", function(){
var imageText = $({{Click Element}}).closest('.d-md-flex').find('.image-wrapper img.image__desktop').attr("alt");
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'studyDesignInteraction',
'action': imageText
});
});
});
return true;
}
}
第一次点击会返回两个事件,并且每次事件后都会加倍。怎样才能只一键申请?
I have a website where there are three different modal buttons and I wrote a variable to get the values in a data layer which is working good but when I first click on the button I get 2 events and it starts doubling up for each click afterwards.
Here is my code
function() {
if ({{Click Text}} == 'STUDY DESIGN'){
$(this).each(function() {
$(this).on("click", function(){
var imageText = $({{Click Element}}).closest('.d-md-flex').find('.image-wrapper img.image__desktop').attr("alt");
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'studyDesignInteraction',
'action': imageText
});
});
});
return true;
}
}
The first click comes back with two events and it keeps doubling up after each event. How can I only apply to one click?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$(this)您的代码是
窗口
$(this) in your code is
window