给你个例子参考一下(摘自以前的帖子):
<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="<img>"><BR>
<INPUT TYPE="button" VALUE="我要在光标处插入上面文本框里输入的文字!"  ONCLICK="insertAtCaret(this.form.aTextArea, this.form.aText.value);">
</FORM>
</BODY>
</HTML>

解决方案 »

  1.   

    给你个例子。你改改吧!<script>
    function test(){
    var str="<br><input><input type='checkbox'><input type='radio' name=a><input type='radio' name=a><input type='radio' name=a>"
    document.all.mxh.insertAdjacentHTML("afterBegin",str)
    }
    </script>
    <div id=mxh></div>
    <input type=button value=insert onclick="test()">
      

  2.   

    to:thinkover(至真宝)
    createTextRange方法不能用于div。to:grooving(峡谷)
    insertAdjacentHTML只有beforeBegin,afterBegin,beforeEnd,afterEnd四个参数,还不能实现在中间插入啊麻烦大家再指点一下了,