<body><script language="JavaScript">
function getCursorPos(event){
var obj= event.target||event.srcElement;
if(document.selection){
if(obj.tagName!=undefined&&obj.tagName=='INPUT'){
var s=document.selection.createRange();
s.setEndPoint("StartToStart",obj.createTextRange());
var pos=s.text.length;
}else{
var rng = obj.createTextRange();
rng.moveToPoint(event.x,event.y);
rng.moveStart("character",-obj.value.length);
var pos=rng.text.length ;
}
}else{
var pos=obj.selectionStart;
}
trace("位置:"+pos);
}
</script>
<form name="form1" method="post"> <textarea name="username1" type="text" id="username1" onClick="getCursorPos(event)">1234567890</textarea> <inPut name="username" type="text" id="username" value="123456789" onClick="getCursorPos(event)"> </form><div id="dbg"></div></body>
我的QQ群:
PHPer&Webgame&移动开发,群号:95303036