Set text-cursor position in a textarea

前端 未结 6 2080
眼角桃花
眼角桃花 2021-01-01 13:18

I\'m working on a BBCode editor and here is the code:

var txtarea = document.getElementById(\"editor_area\");

            function boldText() {
                     


        
6条回答
  •  鱼传尺愫
    2021-01-01 13:55

    Through JQuery:

        var cursorPos = $('#textarea').prop('selectionStart');
        $('#textarea').prop('selectionEnd',cursorPos-2);
    

提交回复
热议问题