<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获取光标坐标</title>
<style type="text/css">
html,body { padding:0; margin:0; }
#textarea {
font-family:Tahoma, Arial;
width:528px;
height:66px;
resize:none;
line-height:21px;
margin:4px 0 0 4px;
padding:3px 5px;
overflow-y:auto;
font-size:14px;
border:1px solid #D0D0D0;
word-wrap:break-word;
word-break:break-all;
border-radius:6px;
-moz-border-radius:6px;
-webkit-border-radius:6px;
transition:border linear .2s, box-shadow linear .2s;
-moz-transition:border linear .2s, -moz-box-shadow linear .2s;
-webkit-transition:border linear .2s, -webkit-box-shadow linear .2s;
outline: none;
}
#textarea:focus {
border-color:#7BD6F6;
-moz-outline:4px solid #E2F5FB;
-moz-outline-radius:8px;
-webkit-box-shadow:0 0 10px rgba(123, 214, 246, .6);
box-shadow:0 0 10px rgba(123, 214, 246, .6);
}
#focus {
position:absolute;
top:0;
top:0;
z-index:9;
font-size:36px;
background:#C30;
color:#FFF;
text-align:center;
margin-left:-18px;
/*margin-top:-12px;*/
}
</style>
<script type="text/javascript" src="caretposition.js"></script>
<script type="text/javascript">
window.onload = function () {
var elem = document.getElementById("textarea");
var focus = document.getElementById("focus");

var input = function () {
var pos = textareaTools.getInputOffset(elem, true);
focus.style.left = pos.left + 'px';
focus.style.top = pos.top + 'px';
focus.style.display = 'block';
document.getElementById('log').innerHTML = 'left:' + pos.left + '; top:' + pos.top;
};
textareaTools._addEvent(elem, 'input', input);
textareaTools._addEvent(elem, 'propertychange', input);
textareaTools._addEvent(elem, 'click', input);
};
</script>
</head>
<body style="background:#FBFCFD;">
<div id="demo" style="margin:auto; text-align:center;">
  在文本框中输入内容试试:<br>
  <textarea id="textarea" style="width:300px;height:100px;"></textarea>
  <div id="log" style="padding:5px 0; font-size:12px"></div>
  <div id="focus" style="display:none">&#x21E7;</div>
</div>
</body>
</html>      
        _getStyle: 'getComputedStyle' in window ? function (elem, name) {
                return getComputedStyle(elem, null)[name];
        } : function (elem, name) {
                return elem.currentStyle[name];
        },