$("#insertMsg").on("click",function(){
  //获取下拉选项框的值
    var textFeildValue = $("#text_type").find("option:selected").text();
    //获取textarea的值    
    var myField=document.getElementById("text_smsnr");
    if (document.selection) {//IE浏览器
           myField.focus();
           sel = document.selection.createRange();
           sel.text = "{"+textFeildValue+"}";
           sel.select();
     }else if (myField.selectionStart || myField.selectionStart == '0'){//火狐/网景 浏览器
       //得到光标前的位置
       var startPos = myField.selectionStart;
       //得到光标后的位置
       var endPos = myField.selectionEnd;
       // 在加入数据之前获得滚动条的高度
       var restoreTop = myField.scrollTop;
       myField.value = myField.value.substring(0, startPos) + "{" + textFeildValue +"}" + myField.value.substring(endPos, myField.value.length);
       //如果滚动条高度大于0
       if (restoreTop > 0) {
         // 返回
         myField.scrollTop = restoreTop;
       }
//                   myField.focus();
       myField.selectionStart = startPos + "{"+textFeildValue.length+"}";
       myField.selectionEnd = startPos + textFeildValue.length;
     }
     else {
       myField.value += "{"+textFeildValue+"}";
//                   myField.focus();
     }
})

 鼠标点击textarea后,在光标后追加内容

 

相关文章:

  • 2022-12-23
  • 2021-11-15
  • 2021-12-19
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2021-08-17
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案