使用 JS 将值添加到隐藏表单字段
我正在尝试使用 JS 和谷歌标签管理器将字符串插入表单隐藏字段。
这是脚本/方法(适用于一堆不同的形式)
(function(){
var selector1 = $('[id="label-utm_source-f7d353cc-c056-400e-a41a-2b022eaf4340_7665"]')
$(selector1).val('{{Read UTM Medium cookie}}');
})();
</script>
或
var selector1 = $('input name="utm_original_lead_source"')
$(selector1).val('{{Read cookie-UTM source}}');
没有任何效果。知道我在这里缺少什么吗?
谢谢你!
这是表单字段:
I am trying to insert a string into the form hidden field using JS and google tag manager.
This is the script/method (worked on a bunch of different forms)
(function(){
var selector1 = $('[id="label-utm_source-f7d353cc-c056-400e-a41a-2b022eaf4340_7665"]')
$(selector1).val('{{Read UTM Medium cookie}}');
})();
</script>
or
var selector1 = $('input name="utm_original_lead_source"')
$(selector1).val('{{Read cookie-UTM source}}');
And nothing worked. Any idea what I'm missing here ?
Thank you!
This is the form field:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CSS选择器实际上是字符串。因此,这是无法使用的:
应该是这样的:
这也是错误的:
应该这样:
A css selector is actually a string. So this cannot work:
it should be something like this:
This is also wrong:
And should be like this: