javascript - 如何在 jQuery 中使用 PHP 变量(在 Wordpress 插件中)

标签 javascript php wordpress variables

This is wordpress plugin code 以下代码有效,但没有文本进入模态窗口。错误是这个enter image description here

     <?php
            $phpvariabletext =  get_post_meta( $post_id, '_billing_satis_sozlesme', true );
            // $phpvariabletext large text along with html codes

            ?>
            <a class="classa" id="view" onclick="openmodal()"> Show Contract </a>

            <script type="text/javascript">
            var content = '<?php echo $phpvariabletext; ?>';
            var newmodal = new tingle.modal();
             function openmodal() {
                newmodal.open();
                newmodal.setContent(content);
            }
        </script>

最佳答案

您可以在 JQuery/Javascript 中使用 PHP 变量,轻松检查以下步骤

1) 将 PHP 变量值作为隐藏类型存储在 HTML 输入标签中

<input type="hidden" value="<?php echo $phpvariabletext;?>" id="phpvariable">

2) 在 HTML 输入标签中分配变量值后。您可以在 JQuery/Javascript 中获取值。

<script type="text/javascript">
        var content = $('#phpvariable').val();
        var newmodal = new tingle.modal();
         function openmodal() {
            newmodal.open();
            newmodal.setContent(content);
        }
</script>

关于javascript - 如何在 jQuery 中使用 PHP 变量(在 Wordpress 插件中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58336747/

相关文章:

php - 在wordpress中获取帖子的所有图像

html - 如何更改我的 wordpress 网站上图像和文本的对齐方式?

javascript - 允许网络用户从色轮上进行颜色选择

javascript - 如何将后端(python、flask)与前端(html、css、javascript)连接起来

php - 如何使用准确的帖子标题进行查询

php - MySQL 内部连接来自另一个表的计数

php - php服务器中的Android应用内计费签名验证

c# - 将指定的月数添加到值的 DateTime

javascript - Dojo 和 RequireJS : Error: defineAlreadyDefined(…) when using both on a site

javascript - PHP在同一页面显示结果