[英]How to Datalayer.push a checkbox variable
I was hoping if somebody could help me figure out how to get datalayer.push
data from checkboxes the user has selected on a form during submission.我希望有人能帮我弄清楚如何从用户在提交期间在表单上选择的复选框中获取
datalayer.push
数据。 The form has many fields but I only want the checkboxes that have been selected.表单有很多字段,但我只想要已选中的复选框。
You need to check when you are calling dataLayer.push
您需要检查何时调用
dataLayer.push
If the function is called after document.ready
or on change or on form submit-event.如果在
document.ready
之后或在更改或表单提交事件后调用该函数。 As the case could be that the value of the checkbox is undefined
at the time of dataLayer.push
function call.在这种情况下,复选框的值可能在
dataLayer.push
函数调用时undefined
。
To get the value of checked checkbox use: $('.form-check__input:checked').serialize();
要获取选中复选框的值,请使用:
$('.form-check__input:checked').serialize();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.