当前位置: 代码迷 >> JavaScript >> javascript textarea moveend选汉语本
  详细解决方案

javascript textarea moveend选汉语本

热度:120   发布时间:2012-10-24 14:15:58.0
javascript textarea moveend选中文本

//获取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"

  相关解决方案