| |
技术文档>>JAVA>>新手入门>>基础入门>查看文档 |
|
| |
用javascirpt在中插入元素(光标位置),大家看看! |
|
| |
文章作者:未知 文章来源:水木森林 |
|
| |
查看:277次 录入:管理员--2007-11-17 |
|
| |
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; } else textel.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>
|
|
|