douyun7285 2016-11-09 11: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 12:37
    关注

    Try this :

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部