87,910
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<script type="text/javascript">
function InsertText(obj,charvalue)
{
obj.focus();
var leng=obj.value.length;
if(typeof document.selection !="undefined") //ie
{
var r =document.selection.createRange();
r.text = charvalue;
}
else //firefox
{
obj.value=obj.value.substr(0,obj.selectionStart)+ charvalue +obj.value.substring(obj.selectionStart,leng);
}
}
</script>
</head>
<body>
<input type="button" value="按钮" onclick="InsertText(x,'aa')" /><br />
<textarea id="x" rows="4" cols="50">
光标位置插入字符光标位置插入字符光标位置插入字符光标位置插入字符光标位置插入字符
</textarea>
</body>
</html>