<textarea id=txt1 onclick="puttext()"></textarea>
<SCRIPT LANGUAGE="JScript">
function puttext(){
var sel = document.selection;
if (sel!=null) {
var rng = sel.createRange();
if (rng!=null)
rng.text= "ok?";
}
}
</SCRIPT>
<SCRIPT LANGUAGE="JScript">
function puttext(){
var sel = document.selection;
if (sel!=null) {
var rng = sel.createRange();
if (rng!=null)
rng.text= "ok?";
}
}
</SCRIPT>
解决方案 »
- jquery 在 hover(或mouseover+mouseout) 中使用 offset的问题
- 为什么onscroll事件在firfox下黑屏的?
- 实现类似土豆网上顶部菜单栏的效果,200分
- 一段JS代码,大家帮忙解释一下??谢谢!
- EXTjs通过表单按钮提交参数返回数据显示到grid中
- 如何在js里进行全文的字符串替换
- 急!如何在一个frame中得到其当前页面的URL
- 请问如何得到一个对象在页面里的绝对位置呢?
- setTimeout出现问题
- jquery 或jquery mobile实现限制Input只能输入指定字符
- 哪位大哥能给我讲讲 prototype的概念和用法,感谢!我查了资料,还是不怎么理解
- 好象比较困难。src问题
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>
<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>