<script type="text/javascript">
function getPosition(obj) {
var result = 0;
if (obj.selectionStart) { //非IE浏览器
result = obj.selectionStart
}
else
{ //IE
var rng;
if (obj.tagName == "TEXTAREA") { //如果是文本域
rng = event.srcElement.createTextRange();
rng.moveToPoint(event.x, event.y);
}
else
{ //输入框
rng = document.selection.createRange();
}
rng.moveStart("character", -event.srcElement.value.length);
result = rng.text.length;
}
return result;
}
function getValue(obj) {
var pos = getPosition(obj);
alert(obj.value.substr(obj.value.substr(0, pos)+pos, obj.value.length));
//alert(obj.value.substr(0, pos) + " [这里是添加的内容] " + obj.value.substr(pos, obj.value.length));
}
</script>
<input id="Text1" onmouseup="getValue(this)" type="text" />