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/