如何在文本区域中设置值

时间:2016-11-09 19:59:01

标签: php textarea

我使用codemirror.net在操场上工作,效果很好。我的下一步是让auto load为文件路径名设置一个值,每个textarea将从.html,.css和jquery加载文件路径。

目前在codemirror中显示

<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>

预览textarea的结果显示&#34; Hello world&#34;因为在javascript中显示

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

所以我在这样的代码镜像中更改设置值。

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

当我在文本区域内看到HTML代码但无法在文本区域中看到预览时,这非常有用。

所以我试图通过

来解决这个问题
<?php echo file_get_contents('testcode.php');?>

我想在javascript中进行更改

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

我的问题是如何在javascript文件中用PHP编写代码。

我试过

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

它不起作用。

任何其他想法如何解决这个问题,使两者都有效!

非常感谢。

AM

1 个答案:

答案 0 :(得分:0)

试试这个:

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