简体   繁体   中英

how to get text in between cursor start and end of textarea

how to get text in between cursor start and end of textarea in html page.

Can someone help me please, i have searched for this but i didnt find any related answers.

any functions like cursor start and cursor end.

can the following could be used

var selection = rangy.getSelection(),  // Whole lot of information, supports
                                       // multi-selections too.
    start   = selection.anchorOffset,  // Start position
    end     = selection.focusOffset;   // End position

Demo

<textarea cols="50" rows="10" id="tarea"></textarea>
<button id="btn">get text</button>


$('#btn').on('click',function(){
    cursor = $('#tarea').prop("selectionStart");
    area = $('#tarea');
    console.log(area.val().substring(cursor,area.val().length));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM