📅  最后修改于: 2022-03-11 15:03:48.958000             🧑  作者: Mango
var userSelection
function countLineBreaks(){
//Textarea
var textarea = document.getElementById("textArea");
//Get user selection
userSelection = (textarea.value).substring(textarea.selectionStart,textarea.selectionEnd);
//Simple regex to check for line break
var matches = userSelection.match(/\n/g);
//Count line breaks
var lineBreaksCount = matches ? matches.length : 0
console.log(lineBreaksCount + ' Line breaks')
}