wordpress - 在 jquery 中添加联系 form7 简码
问题描述
我正在尝试在我的 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 添加短代码,但也许有解决方案以这种方式添加短代码?
解决方案
I don't think you can achieve this using jquery as jquery will only work after the webpage is loaded into the browser, so even if you add a shortcode using jquery it will be of no use as the shortcodes are rendered on server and not in browser.
But you can achieve this using ajax.
推荐阅读
- docker - gpg keyserver 接收失败 没有名字
- c++ - 由于没有文件或目录,在 VSC 上运行代码的问题
- r - 具有不同长度项目的(已经很宽的)数据的复杂重组
- r - 数据框中不同值的人口金字塔
- kubernetes - 如何让 pod 在 Kubernetes 上以 Flink 应用模式暴露 prometheus 监控端口?
- azure-devops - Azure DevOps - 看不到积压中的许多工作项
- spring - 是否有任何最佳实践来审核 Spring Rest 应用程序?
- python-3.x - 如何使不和谐机器人定时静音自动 5 分钟?
- r - 在 R 中创建具有匹配名称的较小向量子集的子集数据框
- file - 文件路径访问权限