<html> <head> <script type=‘text/javascript‘> function test(str){ var tc = document.getElementById("mytextarea"); var tclen = tc.value.length; tc.focus(); if(typeof document.selection != "undefined") { document.selection.createRange().text = str; } else { tc.value = tc.value.substr(0,tc.selectionStart)+str+tc.value.substring(tc.selectionStart,tclen); } } </script> </head> <body> <textarea rows=5 name=s1 cols=27 id="mytextarea">目的通过点击页面上的按钮button 在textarea中的光标停留处插上文字 </textarea> <input type=button onclick="test(‘tt‘)" /> </body> </html>
转:http://blog.csdn.net/xyzqiang/article/details/7003575
时间: 2024-10-10 00:34:00