用javascirpt在<TEXTAREA>中插入元素(光标位置),大家看看!

作者:简简单单 2008-01-18
HTML>
    
T>    
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;
    
}    
    
    
    

    

    





 

相关文章

精彩推荐