textarea에서 5 번째 줄 이후의 모든 문자가 삭제 될 수있는 기능이 필요합니다. 번째 줄에는 최대 15 개의 문자 만 포함됩니다.5 번째 줄 이후의 텍스트 영역에서 문자 삭제
내가 "캐럿"을 사용하여이 조금을 달성 할 수 있지만, 그것은 단지 kepress 이벤트 및 텍스트 영역에서 여분의 텍스트를 지 웁니다하여 setInterval (텍스트 영역의 onfocus 및) 함수 를 사용하여, 특정 커서 위치에 메신저 텍스트를 추가하며, 됨 clearInterval (텍스트 영역의 및 onblur)은 광고를 포함
function insertTextAtCaret(el, text)
{
var val = el.value, endIndex, range;
if (typeof el.selectionStart != "undefined" && typeof el.selectionEnd != "undefined") {
endIndex = el.selectionEnd;
el.value = val.slice(0, endIndex) + text + val.slice(endIndex);
el.selectionStart = el.selectionEnd = endIndex + text.length;
} else if (typeof document.selection != "undefined" && typeof document.selection.createRange != "undefined") {
el.focus();
range = document.selection.createRange();
range.collapse(false);
range.text = text;
range.select();
}
}
선 배치로 인해 중단? –
네, 한 줄에 15 자 뒤에 \ n을 삽입하고 최대 총 5 줄이 필요합니다. – SML
그리고 시작 색인이있는 텍스트를 삭제하는 방법에 대해 고민하고 계신가요? –