问题:JavaScript 中的点击元素存在问题。

huangapple go评论64阅读模式
英文:

Problem with my click element in Javascript

问题

I can't make an alert in JS when clicking on the "Submit" button. It's html loaded remotely by a script and the JS can't recognize it.

Here is a reconstruction, anyone have an idea please? Link to the example

<script charset="utf-8" type="text/javascript" src="//js-eu1.hsforms.net/forms/embed/v2.js"></script>
<script>
  hbspt.forms.create({
    region: "eu1",
    portalId: "26927362",
    formId: "46123717-093e-4314-9afb-d71fc6e2e40f"
  });
</script>
英文:

I can't make an alert in JS when clicking on the "Submit" button. It's html loaded remotely by a script and the JS can't recognize it.

Here is a reconstruction, anyone have an idea please? http://jsfiddle.net/sdrvqjxn/1/

&lt;script charset=&quot;utf-8&quot; type=&quot;text/javascript&quot; src=&quot;//js-eu1.hsforms.net/forms/embed/v2.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  hbspt.forms.create({
    region: &quot;eu1&quot;,
    portalId: &quot;26927362&quot;,
    formId: &quot;46123717-093e-4314-9afb-d71fc6e2e40f&quot;
  });
&lt;/script&gt;

答案1

得分: 1

设置onFormSubmit选项:

hbspt.forms.create({
	region: "eu1",
	portalId: "26927362",
	formId: "46123717-093e-4314-9afb-d71fc6e2e40f",
	onFormSubmit() {
	    alert('submit');
	}
});
英文:

Set the onFormSubmit option:

hbspt.forms.create({
	region: &quot;eu1&quot;,
	portalId: &quot;26927362&quot;,
	formId: &quot;46123717-093e-4314-9afb-d71fc6e2e40f&quot;,
	onFormSubmit() {
	    alert(&#39;submit&#39;);
	}
});

huangapple
  • 本文由 发表于 2023年2月6日 03:23:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75354914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定