Jquery在textarea的文字焦點中插入文字




遇到一個功能,要求點擊標題,插入文字到已有的文本中。
主要代碼如下:

var txtArea = $("#textArea")[0];
            var content = txtArea.value;
            var start = txtArea.selectionStart; //初始位置
            txtArea.value = content.substring(0, txtArea.selectionStart) + $(this).text() + content.substring(txtArea.selectionEnd, content.length);
            var position = start + $(this).text().length;
            $("#textArea").focus();
            txtArea.setSelectionRange(position, position);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM