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; }');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么在stm32门禁成品上增加记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 解riccati方程组