입력 필드가있는 양식이있는 특정 웹 페이지를 방문하고이 입력 필드에 입력 된 모든 행이 양식에서 "Return"을 누른 후 일부 div와 같은 동일한 브라우저 요소에 저장되기를 원한다고 가정 해 보겠습니다. 예를 들면 :
양식을 제출할 필요없이 실시간으로 저장되기를 원합니다. 즉, (주황색 배경) 메모는 양식의 모든 행을 "듣고"Return 키를 누른 후 복사해야합니다.
이 방법으로 메모를 만들 수 있습니다.
스타일:
.note {position: fixed; bottom: 0; right: 0; width: 500px; height: 500px; background: orange}
행동:
let x = document.createElement('div');
x.class.classList.add('note');
다음과 같이 듣고 싶은 입력 필드를 선택할 수도 있습니다.
document.querySelector('.myInputField');
But how could I make sure any row of text written in the input field, is actually copied to the note after hitting Return, in real time?
I need the note's content not to be deleted if I mistakenly refresh the webpage.
I tried to use this code to copy text from the input field to the div in each "Return" press inside the input field, but it doesn't work:
myInputField.addEventListener('keydown', (k)=>{
if ( keyCode == 13 ) {
myInputField.textDocument = myNote.textDocument;
}
});
(At first I used identicality as with ===
but saw I need an assignment like =
).
Here's my recommendation:
update
좋은 시도이지만 keyCode는 실제로 k의 속성이며 이러한 방식으로 액세스 할 수 있습니다. 또한 내가 올바르게 이해했다면 메모의 innerHTML을 입력 필드의 값으로 설정하고 싶다고 생각합니다.
myInputField.addEventListener('keydown', (k)=>{
if ( k.keyCode == 13 ) {
myNote.innerHTML = myInputField.value;
}
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다