复制代码代码如下:
<脚本类型=“ text/javascript”>
函数gettxt1cursorPosition(){
var otxt1 = document.getElementById(“ txt1”);
var cursurPosition = -1;
if(otxt1.selectionstart){//非IE浏览器
cursurPosition = otxt1.selectionstart;
} else {// ie
var range = document.Selection.Createange();
range.movestart(“ tarne”,-otxt1.value.length);
cursurposition = range.text.length;
}
警报(culsurposition);
}
函数settxt1cursorPosition(i){
var otxt1 = document.getElementById(“ txt2”);
var cursurPosition = -1;
if(otxt1.selectionstart){//非IE浏览器
OTXT1.SelectionStart = i;
} else {// ie
var范围= otxt1.createtExtrange();
range.move(“字符”,i);
range.Select();
}
}
函数getta1cursorPosition(){
var evt = window.event?window.event:getTa1cursorPosition.caller.arguments [0];
var ota1 = document.getElementById(“ ta1”);
var cursurPosition = -1;
if(ota1.selectionstart){//非IE浏览器
cursurPosition = ota1.selectionstart;
} else {// ie
var范围= ota1.createtExtrange();
range.MovetOpoint(evt.x,evt.y);
range.movestart(“ tarne”,-ota1.value.length);
cursurposition = range.text.length;
}
警报(culsurposition);
}
函数setta1cursorPosition(i){
var ota2 = document.getElementById(“ ta2”);
if(ota2.selectionstart){//非ie浏览器
ota2.selectionstart = i;
ota2.selectionend = i;
} else {// ie
var范围= ota2.createtExtrange();
range.move(“字符”,i);
range.Select();
}
}
</script>