douchun6108 2017-03-11 10:01
浏览 28
已采纳

如何从php数组获取这个javascript数组?

I have a javascript array

<script>
var image = document.getElementById('example-basic');

var options = {};
var data = [
  Taggd.Tag.createFromObject({
    position: { x: 0.19, y: 0.4 },
    text: 'This is a tree',
  }),
  Taggd.Tag.createFromObject({
    position: { x: 0.5, y: 0.3 },
    text: 'Pretty sure this is also a tree',
  }),
  Taggd.Tag.createFromObject({
    position: { x: 0.775, y: 0.5 },
    text: 'Can you guess this one?',
  }),
];

var taggd = new Taggd(image, options, data);
</script>

I need to create a PHP array and covert it into this javascript array can you please help me?

  • 写回答

3条回答 默认 最新

  • dongtun1872 2017-03-11 10:10
    关注

    I am not an expert in PHP, but I am sure you could output an html from php:

    <script type='text/javascript'>
     var js_ar = <?php echo json_encode($array); ?>
    </script>
    

    js_ar will be a global variable when javascript is executed on browser and can be easily accessed. I would leave variable naming up to you.

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

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法