【问题标题】:add contact form7 shortcode in jquery在 jquery 中添加联系 form7 简码
【发布时间】: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


    【解决方案1】:

    我不认为你可以使用 jquery 来实现这一点,因为 jquery 只有在网页加载到浏览器后才能工作,所以即使你使用 jquery 添加短代码它也没有用,因为短代码是在服务器上呈现的而不是在浏览器中。

    但是你可以使用 ajax 来实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      相关资源
      最近更新 更多