时间: 2021-07-31 作者:daque
html><head><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;}elsetextel.value= text;}</script></head><body><form name="aform"><textarea name="atextarea" rows="5" cols="80" wrap="soft"onselect="storecaret(this);" onclick="storecaret(this);" onkeyup="storecaret(this);">这是例子,你不妨在这边增添笔墨、插入笔墨。 </textarea><br><input type="text" name="atext" size="80" value="我要在光标处插入那些笔墨"><br><input type="button" value="我要在光标处插入上头文本框里输出的笔墨!"onclick="insertatcaret(this.form.atextarea, this.form.atext.value);"></form></body></html>