会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
海浪
博客园
首页
新随笔
订阅
管理
文本框内插入文字代码,删除选中文本代码
HTML代码
<script> function storeCaret (textEl) { if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate(); } function insertAtCaret (textEl, text) { if (textEl.createTextRange && textEl.caretPos) { var caretPos = textEl.caretPos; caretPos.text =caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?text + ' ' : text; } else textEl.value = text; } function deleteAtCaret (textEl) { if (textEl.createTextRange && textEl.caretPos) { var caretPos = textEl.caretPos; document.selection.clear(); } //alert(aForm.aTextArea. } </script> <form name=aForm> <input name=aTextArea size=120 wrap=soft onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" value=这是例子,你可以在这里添加文字、插入文字。> <br> <input type=text name=aText size=80 value=我要在光标处插入这些文字><br> <input type=button value=我要在光标处插入上面文本框里输入的文字! onclick="insertAtCaret(this.form.aTextArea, this.form.aText.value);"> <input type=button value=删除选中文字 onclick=deleteAtCaret(this.form.aTextArea); id=button1 name=button1> </FORM>
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
posted @
2007-02-01 15:21
海浪~~
阅读(
538
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告