textarea插入字符问题
请问在textarea区域里面,光标当前位置,点击按钮插入指定字符该怎样实现的?
我现在找到的代码都只能在区域最后面加上...
谢谢帮忙
问题点数:20、回复次数:3Top
1 楼meizz(梅花雪)回复于 2006-03-20 11:49:02 得分 8
textarea.focus();
document.execCommand('Paste');Top
2 楼shuzai()回复于 2006-03-20 12:33:31 得分 0
谢谢meizz(梅花雪)
不过这个好像是粘贴内存的信息.
我需要插入字符好像不行的.
比如我的a按钮点击一下,在光标位置插入字母a, b按钮点击一下就插入字母bTop
3 楼clare2003(忘情火)回复于 2006-03-20 12:48:33 得分 12
第一种:
oTextarea.focus();
document.selection.createRange().text+=strText;
oTextarea.blur();
第二种:
clipboardData.setData("text",strText);
oTextarea.focus();
document.execCommand("paste");
////////////////////////////
<textarea id=demo>abcdef</textarea>
<input type=button onclick=addText(demo,"1234") value=1 ID=Button1>
<input type=button onclick=addText2(demo,"1234") value=2 ID=Button2>
<script>
function addText(oTextarea,strText){
oTextarea.focus();
document.selection.createRange().text+=strText;
oTextarea.blur();
}
function addText2(oTextarea,strText){
clipboardData.setData("text",strText);
oTextarea.focus();
document.execCommand("paste");
}
</script>
Top




