日期:2014-05-16 浏览次数:20333 次
//获取textare选中的文本 function getFieldSelection(id) { var select_field = document.getElementById(id); word=''; if (document.selection) { var sel = document.selection.createRange(); if (sel.text.length > 0) { word = sel.text; } } /*ie浏览器*/ else if (select_field.selectionStart || select_field.selectionStart == '0') { var startP = select_field.selectionStart; var endP = select_field.selectionEnd; if (startP != endP) { word = select_field.value.substring(startP, endP); } } /*标准浏览器*/ return word; } //高亮显示 function chooseText(target,start,end,len) { var target = document.getElementById(target); if(target.createTextRange){//IE浏览器 var range = target.createTextRange(); range.moveEnd("character",end-len); // range.moveEnd("character",len-end); range.moveStart("character",start); range.select(); }else{ target.setSelectionRange(start,end); target.focus(); } }
?http://www.zhangxinxu.com/study/201004/textarea-text-select-demo.html
对input框取消默认的提示框用?autocomplete="off"