原理就把编辑器的innerHTML或value
显示到预览的div里去

解决方案 »

  1.   

    用getElectmentbyID("ID")
    或getElectmentbyName("name")
    得到你输入值的textarea,
    右边预览的地方就不用说了.
    <script language="JavaScript" type="text/javascript">
    function prev(){
      var op=document.getElementsByName("textin").innerHTML;
      document.getElementById("Layer1").innerHTML=op;}
    </script>
    <textarea name="textin" cols="20" rows="5" onkeypress="prev();"></textarea>
    <div id="Layer1"></div>
      

  2.   

    如果你用的是iframe的话这些代码应该管用//IE
    document.execCommand('bold',false,null);
    document.execCommand('italic',false,null);
    document.execCommand('underline',false,null);//Netscape
    $('edit').contentWindow.document.execCommand('bold',false,null);
    $('edit').contentWindow.document.execCommand('italic',false,null);
    $('edit').contentWindow.document.execCommand('underline',false,null); 如果要写快捷键如ctrl+b这些的话, Firefox要用addEventListener
      

  3.   

    哦, 8好意思, 看错你的意思了
    <script language="javascript" type="text/javascript">//打开时focus在输入框内
    window.onload = function() {
    $('shuru').focus();
    }//更新内容
    function xianshi(t) {
    $('xianshi').innerHTML = t.value;
    }//简化getElementById
    var $ = function($) {
    return document.getElementById($);
    }</script><body><input type="text" maxlength="10" size="10" id="shuru" onkeyup="xianshi(this)"/>
    <span id="xianshi"></span></body>
    演示: http://deepblue.camosun.bc.ca/~cst08017/xzp/jsgx
      

  4.   

    <script language="JavaScript" type="text/javascript"> 
    function prev(){ 
      var op=document.getElementsByName("textin").value; 
      document.getElementById("Layer1").innerHTML=op; } 
    </script> 
    <textarea name="textin" cols="20" rows="5" onkeypress="prev();"> </textarea> 
    <div id="Layer1"> </div> 
      

  5.   

    <script language="JavaScript" type="text/javascript"> 
    function prev(){ 
      var op=document.getElementById("textin"); 
      document.getElementById("Layer1").innerHTML=op.value; 

    </script> 
    <textarea id="textin" cols="20" rows="5" onkeypress="prev();"> </textarea> 
    <div id="Layer1"> </div>