try something like<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>

解决方案 »

  1.   

    怪异的写法(临时想的):效率应该比前者好多了,呵呵
    <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();
    var t = document.body.createTextRange();
    r.moveToElementText(cell);
    var oRcts=r.getClientRects()
    for(i=0;i<oRcts.length;i++){
      t.moveToPoint(oRcts[i].left, oRcts[i].top);
      r.setEndPoint('StartToStart',t);
      if(oRcts.length==i+1)
       t.moveToPoint(oRcts[i].right, oRcts[i].bottom);
      else
       t.moveToPoint(oRcts[i].left, oRcts[i].bottom);
      r.setEndPoint('EndToEnd',t);
      r.select();alert(r.text);
    }
    }
    </script>