요소가있는 contenteditable div가 있습니다. 필자가 원하는 것은 Enter 키를 누를 때 현재 캐럿이있는 요소 바로 다음에 새 단락 태그를 작성하는 것입니다.contenteditable div에 새 요소를 작성한 후 캐럿을 설정하십시오.
http://jsfiddle.net/qcf4d/1/ : I Enter 키를 누르면 내가 단락 태그를 만들 수 있습니다,하지만 난 캐럿이 바로 폐쇄 </P 여기 >
전에 단락 태그의 텍스트 끝에 배치 할 데모입니다
$(document).on('keypress', 'div[contenteditable="true"]', function(event) {
//enter key
if (event.which == 13) {
//insert the paragraph after this element.
$(window.getSelection().anchorNode.parentNode).after("<p>cool</p>");
}
});
생각들? jquery focus() 함수가 도움이 될 것이라고 생각합니다.