Javascript: how to get line/col caret position in textarea?
问题 I can not find the solution. I've tried to assume that count of \n symbols is the same with lines count, but sometimes this method works incorrectly (e.g. after paste text from clipboard) i've tried different jQuery plugins, but still unsuccessfully. any idea? 回答1: Why not just do this: Take the text content only up to selectionStart then make it an array by splitting at eol p = $('#Form_config').val().substr(0, $('#Form_config')[0].selectionStart).split("\n"); // line is the number of lines