gpt4 book ai didi

javascript - dataLayer.push复制了

转载 作者:行者123 更新时间:2023-12-03 07:23:44 24 4
gpt4 key购买 nike

我正在尝试推送dataLayer。但是它一直给我一个重复的数组。请看下面我的代码

<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script>

dataLayer = [{
'productID': '123456',
'productTitle': 'Very awesome product',
'productPrice': '13.00'
}];
function next_step1c() {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'Enquiry',
'PageURL': window.location.href,

});
}
</script>
<fieldset id="firstc">
<div class="funkyradio">
<div class="funkyradio-success" onclick="next_step1c()">
<input type="radio" name="buy" id="check1c" value="Rolex"/>
<label for="check1c">Rolex</label>
</div>
</div>
</fieldset>
当我单击单选按钮时,我得到以下结果。
enter image description here
但是当我单击 劳力士一词时。我正在重复
enter image description here
仅当我单击 Rolex 一词时,如何才能获得一键推力?

最佳答案

尝试这样。
您已将onclick添加到.funkyradio-success类。因此,当您单选按钮clicked时,它仅适用于1时间。但是,当您单击标签按钮时,它就会出现clicks double。因为当您使用click label时,可以在onclick上使用.funkyradio-success。还有label binded to radio input,所以input click trigger也可以。因此,您的函数调用2次。

 dataLayer = [{
'productID': '123456',
'productTitle': 'Very awesome product',
'productPrice': '13.00'
}];
function next_step1c() {
console.log('you clicked me');
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'Enquiry',
'PageURL': window.location.href,

});
}
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>

<fieldset id="firstc">
<div class="funkyradio">
<div class="funkyradio-success" onclick="next_step1c()">
<input type="radio" name="buy" id="check1c" value="Rolex"/>
<label for="check1c">Rolex</label>
</div>
</div>
</fieldset>

添加onclick以输入单选

 dataLayer = [{
'productID': '123456',
'productTitle': 'Very awesome product',
'productPrice': '13.00'
}];
function next_step1c() {
console.log('you clicked me');
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'Enquiry',
'PageURL': window.location.href,

});
}
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>

<fieldset id="firstc">
<div class="funkyradio">
<div class="funkyradio-success" >
<input type="radio" name="buy" id="check1c" onclick="next_step1c()" value="Rolex"/>
<label for="check1c">Rolex</label>
</div>
</div>
</fieldset>

关于javascript - dataLayer.push复制了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64657229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com