<div unselectable="on" align=center style="height:250; width:425;
 background-color:powderblue; border:outset powderblue">
  <br>
  <div id=foo contenteditable align=left 
   style="height:200; width:370;background-color:white; font-face:Arial; padding:3; 
   border:inset powderblue; scrollbar-base-color:powderblue; overflow=auto;">
  </div>
  <br>
 
  <button unselectable="On" onclick='document.execCommand("Bold");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="粗体">
   <B>B</B></button>
  <button unselectable="On" onclick='document.execCommand("Italic");foo.focus();'    
   style="background-color:powderblue; border-color:powderblue" title="斜体">
   <B><I>I</I></B></button>
  <button unselectable="On" onclick='document.execCommand("Underline");foo.focus();'
   style="background-color:powderblue; border-color:powderblue;" title="下划线">
   <B><U>U</U></B></button>
<button unselectable="On" onclick='document.execCommand("StrikeThrough");foo.focus();'
   style="background-color:powderblue; border-color:powderblue; text-decoration=line-through"
   title="删除线">
   <B>S</B></button>
  &nbsp;&nbsp;
 
  <button unselectable="On" onclick='document.execCommand("SuperScript");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="上标">
   <B>^</B></button>
  <button unselectable="On" onclick='document.execCommand("SubScript");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="下标">
   <B>_</B></button>
  &nbsp;&nbsp;
 
  <button unselectable="On" onclick='document.execCommand("InsertOrderedList");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="已排序列表">
   <B>OL</B></button>
  <button unselectable="On" onclick='document.execCommand("InsertUnorderedList");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="未排序列表">
   <B>UL</B></button>
  <button unselectable="On" onclick='document.execCommand("Outdent");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="突出">
   <B>&lt;&lt;</B></button>
  <button unselectable="On" onclick='document.execCommand("Indent");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="缩进">
   <B>&gt;&gt;</B></button>
  &nbsp;&nbsp;
 
  <button unselectable="On" onclick='document.execCommand("JustifyLeft");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="左对齐">
   <B>|&lt;</B></button>
  <button unselectable="On" onclick='document.execCommand("JustifyRight");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="右对齐">
   <B>&gt;|</B></button>
  <button unselectable="On" onclick='document.execCommand("JustifyCenter");foo.focus();'
   style="background-color:powderblue; border-color:powderblue" title="居中">
   <B>&gt;|&lt;</B></button>
  &nbsp;&nbsp;
  <br>
 
  <button unselectable="On" onclick='document.execCommand("Cut");foo.focus();'
   style="background-color:powderblue; border-color:powderblue"><B>剪切</B></button>
  <button unselectable="On" onclick='document.execCommand("Copy");foo.focus();'
   style="background-color:powderblue; border-color:powderblue"><B>复制</B></button>
  <button unselectable="On" onclick='document.execCommand("Paste")'
   style="background-color:powderblue; border-color:powderblue"><B>粘贴</B></button>
  &nbsp;&nbsp;
  <button unselectable="On" onclick='document.execCommand("Overwrite");foo.focus();'
   style="background-color:powderblue; border-color:powderblue"><B>覆盖</B></button>
</div>

解决方案 »

  1.   

    to jnkc(江南昆虫) :怎么用?
      

  2.   

    这个是 saucer(思归, MS .NET MVP)  的去每行的代码,结合jnkc(江南昆虫) 的代码就可以了<table>
    <tr>
     <td>hello world</td><td id=cell width=50>Migrating Your Access Database to Microsoft SQL Server 7.0
    </td><td>world</td>
    </tr>
    </table>
    <input type="button" value="get lines" onclick="getLines()">
    <script language="javascript">
    function getLines()
    {
      var r = document.body.createTextRange();
      r.moveToElementText(cell);
      var rold = r.duplicate();
      r.collapse();
      n=r.boundingHeight;
      while (r.compareEndPoints("EndToEnd",rold) < 0)
      {
    while (n == r.boundingHeight)
      r.moveEnd("character",1); r.moveEnd("character",-1); //get back one char
    alert(r.text);
    r.collapse(false);
    r.moveEnd("character",1);
    n=r.boundingHeight;
      }
    }
    </script>