当前位置:编程学习 > asp >>

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

HTML>
<HEAD>    
<SCRIPT>    
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;
    
}    
</SCRIPT>    
</HEAD>    
<BODY>    
<FORM NAME="aForm">
<TEXTAREA NAME="aTextArea" ROWS="5" COLS="80" WRAP="soft"    ONSELECT="storeCaret(this);" ONCLICK="storeCaret(this);" ONKEYUP="storeCaret(this);">    这是例子,你可以在这里添加文字、插入文字。
 </TEXTAREA>    
<BR>    
<INPUT TYPE="text" NAME="aText" SIZE="80" VALUE="我要在光标处插入这些文字"><BR>
<INPUT TYPE="button" VALUE="我要在光标处插入上面文本框里输入的文字!"    ONCLICK="insertAtCaret(this.form.aTextArea, this.form.aText.value);">
</FORM>
</BODY>
</HTML> 
补充:asp教程,客户端相关打印 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,