js插入字符到textarea的效果代码 时间:2020-05-12 人气:0 www.qb5200.com js插入字符到textarea脚 本之家 <script language="javascript" type="text/javascript"> function grin(tag) { var myField; myField = document.getElementById('content'); if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = tag; myField.focus(); } else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; var cursorPos = endPos; myField.value = myField.value.substring(0, startPos) + tag + myField.value.substring(endPos, myField.value.length); cursorPos += tag.length; myField.focus(); myField.selectionStart = cursorPos; myField.selectionEnd = cursorPos; } else { myField.value += tag; myField.focus(); } } </script> A </textarea> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容