javascript - 使用 php 变量和 javascript 打印 html

标签 javascript php html codeigniter

我的 html 位于 php 变量中,例如 $html,我想使用 javascript 打印此 html。我为此编写了以下代码。

<script>var mywindow = window.open('', 'my div', 'height=400,width=600');
    mywindow.document.write(<?= $html ?>);
    mywindow.print();</script>

如果变量包含普通字符串而不是HTML

,它对我有用

最佳答案

尝试在 write 函数中使用引号,例如,

mywindow.document.write("<?= $html ?>");

关于javascript - 使用 php 变量和 javascript 打印 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38717378/

相关文章:

javascript - 使用 JavaScript 进行解析

javascript - 不明白 Yarn check 警告

javascript - 即时加载 Amazon MP3 小部件

PHP - 删除字符串中 HTML 标签的效果 - 但也显示它们?

javascript - Fancybox问题,需要帮助

javascript - 在不同域上重定向 iframe 的父级 - 替代逻辑

php - 正确使用依赖注入(inject)容器

javascript - 为什么我的减少时间功能不起作用?

html - 即使显式声明,不透明度声明也是从父级继承的

html - 对齐按钮和 div 中的链接,在 IE 中损坏,在 FF 中有效