<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta name="Author" content=""> <title>内容筛选</title>
<script type='text/javascript'>
function getPositions() { var el = document.getElementById('shaixuan'); var startPosition = 0;//所选文本的开始位置 var endPosition = 0;//所选文本的结束位置 if(document.selection) { //IE var range = document.selection.createRange();//创建范围对象 var drange = range.duplicate();//克隆对象
//@todo 获取textarea中,选中的文本 function getshaixuan() { var position = getPositions(); var start = position.start;//开始位置 var end = position.end;//结束位置 var text = document.getElementById('shaixuan').value; var selectText = text.substr(start, (end - start));//textarea中,选中的文本 //alert(selectText); var textBox1 = document.getElementById("canjia"); textBox1.innerText=textBox1.value+selectText; } //]]> </script>