1.取得文本框中鼠标的位置
function test(obj)
{
obj.focus();
var workRange=document.selection.createRange();
var allRange=obj.createTextRange();
workRange.setEndPoint("StartToStart",allRange);
len=workRange.text.length;
alert(len);
}
2.取得文本区中选中的字符
function test(obj)
{
obj.focus();
var sel=document.selection.createRange();
alert(sel.text);
}
3.取得文本区滚动条的位置
textarea.scrollTop
4.在文本区光标所在位置插入字符
function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
} else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}