douyun7285 2016-11-09 19:59
浏览 104
已采纳

如何在文本区域中设置值

I'm working on the playground using from codemirror.net, and is works great. My next step is to have auto load set a value to file path name, each textarea will load file path from .html, .css and jquery.

currently in codemirror showing

<div id="wrap">

  <!-- Code Editors -->   <section id="code_editors">
    <div id="html" class="code_box">
      <h3>HTML</h3>
      <textarea name="html"></textarea>
    </div>
    <div id="css" class="code_box">
      <h3>CSS</h3>
      <textarea name="css"></textarea>
    </div>
    <div id="js" class="code_box">
      <h3>JavaScript</h3>
      <textarea name="js"></textarea>
    </div>   </section>
     <!-- Sandboxing -->   <section id="output">
    <iframe></iframe>   </section>    </div>

The result of preview textarea showed "Hello world" that because in javascript showed

  html_editor.setValue('<p>Hello World</p>');
    css_editor.setValue('body { color: red; }');

so i change set value in codemirror like this.

    <textarea name="html"><?php
echo file_get_contents('testcode.php');
?>
</textarea>
</div>

this works great when I see HTML code inside of text area but unable to see the preview in the text area.

so I'm trying to solve this how to see preview too using

<?php echo file_get_contents('testcode.php');?>

I thought to make change in javascript where it said

html_editor.setValue('<p>Hello World</p>');
    css_editor.setValue('body { color: red; }');

my question is that how can I write code in PHP inside of javascript file.

i tried

html_editor.setValue('<?php echo file_get_contents('testcode.php');?>');
    css_editor.setValue('body { color: red; }');

it does not work.

Any other idea how to solve this to make both works!

many thanks.

AM

  • 写回答

1条回答 默认 最新

  • doumei3828 2016-11-09 20:37
    关注

    Try this :

    var = "<?php echo file_get_contents('testcode.php')?>";
    html_editor.setValue(var );
    css_editor.setValue('body { color: red; }');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮