当前位置: 代码迷 >> Web前端 >> textarea双击剔除一行
  详细解决方案

textarea双击剔除一行

热度:116   发布时间:2012-11-20 09:55:43.0
textarea双击删除一行
<html>
<head>
<script language="javascript">
function delline(){
	var obj = document.getElementById('ice');
    ice.focus();
    var r1 = document.body.createTextRange();
    var r2 = document.body.createTextRange();
    var s  = document.selection.createRange();
    var re = ice.createTextRange().getClientRects();
    var t  = s.getBoundingClientRect().top;
    for(i=0;i<re.length;i++)if(re[i].top>=t)break;
    r2.moveToPoint(re[i].left,re[i].top);
    r1.setEndPoint("StartToStart", r2);
    r2.moveToPoint(re[i].left,re[i].bottom);
    r1.setEndPoint("EndToEnd", r2);
    r1.text = "";
}
</script>
</head>
<body>
<textarea id="ice" rows="10" cols="50" onDblClick="delline()">
测试行1
测试行2
测试行3
</textarea>
</body>
</html>
  相关解决方案