我有一个带有按钮的页面。当用户单击该按钮时,应该打开一个弹出窗口,他应该使用重力形式输入他的联系号码,然后向他显示视频。 现在我在页面上有一个按钮和一个通过 iframe 标签显示视频的 html 元素,默认模式是 display: none。
function custom_script() {
?>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
// Event listener for form submission
jQuery(document).on('gform_confirmation_loaded', function(event, formId){
// Check if the submitted form is the one with ID 1
if (formId == 1) {
// Show the video element with ID 'wb-video'
document.getElementById('wb-video').style.display = 'block';
}
});
});
</script>
<?php
}
add_action('wp_footer', 'custom_script');
我将此代码放在functions.php 文件的末尾。但用户完成表单后,页面上没有任何反应。视频不显示。 谢谢你指导我。
这里使用而不是代码的简单选项是在重力表单设置中提交表单后添加重定向 URL,在该页面上,您可以添加要向用户显示的视频。
这样您就不必在网站上添加脚本。