ITeye博客

Textarea在光标停留处插入文字

cai555 · 2010-03-17 15:51 · javascript · Web前端 · Markdown

<!-- 

function Insert(str) { 
var obj = document.getElementById('content'); 
if(document.selection) { 
obj.focus(); 
var sel=document.selection.createRange(); 
document.selection.empty(); 
sel.text = str; 
} else { 
var prefix, main, suffix; 
prefix = obj.value.substring(0, obj.selectionStart); 
main = obj.value.substring(obj.selectionStart, obj.selectionEnd); 
suffix = obj.value.substring(obj.selectionEnd); 
obj.value = prefix + str + suffix; 
} 
obj.focus(); 
} 
--> 

 兼容IE、firefox

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。