【发布时间】:2020-10-04 20:22:23
【问题描述】:
我正在尝试在我的 jquery 函数中通过简码插入 cf7。在我的脚本中,它就像命中:
<script type="text/javascript">
jQuery(document).on("click", ".helpful #smthWrong", function (e) {
jQuery(".helpful ").html(<?php echo do_shortcode("[contact-form-7 id='107' title='Kontaktų forma 1']"); ?>);
});
</script>
当我在控制台中检查时,出现意外令牌错误
jQuery(".helpful ").html(<div role="form" class="wpcf7" id="wpcf7-f107-o1" lang="lt-LT" dir="ltr">
当我将我的 php 代码包装在 ' ' 中时,我得到了 Uncaught SyntaxError: Invalid or unexpected token 并且结果如下:
jQuery(".helpful ").html('<div role="form" class="wpcf7" id="wpcf7-f107-o1" lang="lt-LT" dir="ltr">
我读到可以使用 ajax 添加短代码,但也许有解决方案以这种方式添加短代码?
【问题讨论】:
标签: wordpress shortcode contact-form-7