JS在指定位置添加内容 WEB页面有个TEXTBOX,旁边一个按钮如何点击按钮在TEXTBOX内鼠标的指定位置添加内容比如TEXTBOX内容为:111222333444这时候如果我鼠标如果定位在111后面,点击旁边的按钮TEXTBOX内容显示为:111测试222333444 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <html> <head> <script type="text/javascript"> 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; } function deleteAtCaret (textEl) { if (textEl.createTextRange && textEl.caretPos) { var caretPos = textEl.caretPos; document.selection.clear(); } //alert(aForm.aTextArea. } </script> </head> <body> <form name=aForm> <input name=aTextArea size=120 wrap=soft onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" value=这是例子,你可以在这里添加文字、插入文字。> <br> <input type=text name=aText size=80 value=我要在光标处插入这些文字><br> <input type=button value=我要在光标处插入上面文本框里输入的文字! onclick="insertAtCaret(this.form.aTextArea, this.form.aText.value);"> <input type=button value=删除选中文字 onclick=deleteAtCaret(this.form.aTextArea); id=button1 name=button1> </form> </body></html> 同志们帮我看看JS里面Function套Function的写法没有问题吧 菜鸟的问题 求一正则表达式 使用FreeTextBox时候JS错误、在线等100分献上 动态删除table行以后,添加时产生的隔行变色如何也跟着变化。 在MEIZZ(梅花雪)老大帮助下完成的通过IFRAME实现的消息提示框程序,请多多指正 javascript xmlhttp问题 Easyui TreeGrid 全部展开后垂直滚动条不显示 javascript中可以使用jsp中的变量吗? 怎麼樣釋放大容量表的內存? 求教js实现图片的旋转 关于webwork2的拦截器两个问题!
<head>
<script type="text/javascript">
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;
}
function deleteAtCaret (textEl) {
if (textEl.createTextRange && textEl.caretPos) {
var caretPos = textEl.caretPos;
document.selection.clear();
}
//alert(aForm.aTextArea.
}
</script>
</head>
<body>
<form name=aForm>
<input name=aTextArea size=120 wrap=soft onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" value=这是例子,你可以在这里添加文字、插入文字。>
<br>
<input type=text name=aText size=80 value=我要在光标处插入这些文字><br>
<input type=button value=我要在光标处插入上面文本框里输入的文字! onclick="insertAtCaret(this.form.aTextArea, this.form.aText.value);">
<input type=button value=删除选中文字 onclick=deleteAtCaret(this.form.aTextArea); id=button1 name=button1>
</form>
</body>
</html>