douzhi3776 2015-11-03 12:27
浏览 61
已采纳

无法将php变量分配给脚本

So i am using this script to copy text to the clipboard that needs to be compatible with firefox and chrome at a minimum.

https://github.com/lgarron/clipboard.js

Basically i have some html stored in a php variable and im trying to copy that to the clipboard.The other way i could do it is to copy the contents of a div to the clipboard but basically same result

<script src="js/clipboard.js"></script>

<script>
    document.getElementById('markup-copy').addEventListener('click', function() {
        var val = '<?php echo $myText ?>';
        clipboard.copy({
            'text/plain': 'Paste this into a HTML editor.',
            'text/html': val;
        }).then(
        function(){console.log('success'); },
        function(err){console.log('failure', err);
        });

    });
</script>";

Ive also tried doing the same but echoing the string directly i.e

'text/html': '<?php echo $myText ?>';

The script does print out the actual string of html however when i copy it to the clipboard all i see is:

<?php echo $myText ?>

So even though the page translates the above to the string, this script doesnt seem to. Any ideas?

The $myText variable is a string with and some basic HTML, no php.

I want to avoid using a flash based solution however if this simply wont work then ill settle to do it in flash.

  • 写回答

2条回答 默认 最新

  • du_1993 2015-11-03 13:00
    关注

    replace

    var val = '<?php echo $myText ?>';

    to

    var val = <?php echo $myText; ?>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒