日期:2014-05-16 浏览次数:20482 次
<script type="text/javascript"> var lastInput = null; window.onload = function () { inputs = document.getElementsByTagName("input"); for (i = 0; i < inputs.length; i++) { if (inputs[i].type.toLowerCase() == "text") { inputs[i].onfocus = function () { lastInput = this; } } } } function AddContent(str) { if (lastInput) { lastInput.focus(); } if (typeof document.selection != "undefined") { document.selection.createRange().text = str; } else { lastInput.value = lastInput.value.substr(0, lastInput.selectionStart) + str + lastInput.value.substring(lastInput.selectionStart, lastInput.value.length); } } </script> </head> <body> <form> <input id="Text1" type="text" /> <input id="Text2" type="text" /> <input id="Text3" type="text" /> <input id="Text4" type="text" /> <input id="Text5" type="text" /> <input id="Text6" type="text" /> <input type="button" onclick="AddContent('新内容')" value="插入" /> </form> </body> </html>