<textarea id="myTextArea" style="WIDTH: 376px; HEIGHT: 160px" rows="10" cols="44"></textarea>
<input type="button" value="插入測試" onclick="InsertContent('myTextArea','我是要插入的文字');">

function InsertContent(AreaID,Content)
{
    var myArea = document.getElementById(AreaID);
 
    //IE
    if (document.selection) 
   {
      myArea.focus();
      var mySelection =document.selection.createRange();
      mySelection.text = Content;
   }
   //FireFox
   else  
  {
     var myPrefix = myArea.value.substring(0, myArea.selectionStart);
     var mySuffix = myArea.value.substring(myArea.selectionEnd);
     myArea.value = myPrefix + Content + mySuffix;
   }
}

arrow
arrow
    全站熱搜

    welkingunther 發表在 痞客邦 留言(0) 人氣()