나는 7 개의 텍스트 필드가있는 html 양식을 가지고 있습니다. 기본값에서 값의 변경을 수신 대기하려면 Javascript 이벤트 리스너가 필요합니다. 이벤트 리스너는 텍스트 붙여 넣기, 놓기 또는 입력 여부에 관계없이 format()이라는 함수를 시작해야합니다. 어떻게하면 좋을까요?값 변경시 양식 텍스트 필드의 코드 이벤트 리스너?
는 아래의 HTML 형태 : 그런데
<form class="right_aligned" name="form" method="get" action="" id="form" >
<div style="float: left;"><input ondblclick="this.value=''" type="text" name="publication" value="Publication..." id="publication" style="border:1px solid;border-color:#B0B0B0;width:225px;padding:4px;margin-left:10px;margin-bottom:10px;margin-top:10px;color: #000;"
ondrop="format()" ondragover="{this.value=''; this.style.color='#000';}" onfocus="if (this.value==this.defaultValue) {this.value=''; this.style.color='#000';}" onblur="if(this.value=='') {this.value=this.defaultValue; this.style.color='#000';}"></div>
<div style="float: left;"><input ondblclick="this.value=''" type="text" name="title" value="Article Title..." id="title" style="border:1px solid;border-color:#B0B0B0;width:225px;padding:4px;margin-left:10px;margin-bottom:10px;margin-top:10px;color: #000;"
onmouseup="format()" ondrop="format()" ondragover="{this.value=''; this.style.color='#000';}" onfocus="if (this.value==this.defaultValue) {this.value=''; this.style.color='#000';}" onblur="if(this.value=='') {this.value=this.defaultValue; this.style.color='#000';}"></div>
<div style="float: left"><input ondblclick="this.value=''" type="text" name="author" value="Author..." id="author" style="border:1px solid;border-color:#B0B0B0;width:225px;padding:4px;margin-left:10px;margin-bottom:10px;margin-top:10px;color: #000;"
onmouseup="format()" ondrop="format()" ondragover="{this.value=''; this.style.color='#000';}" onfocus="if (this.value==this.defaultValue) {this.value=''; this.style.color='#000';}" onblur="if(this.value=='') {this.value=this.defaultValue; this.style.color='#000';}"></div>
<div style="float: left;"><input ondblclick="this.value=''" type="text" name="credentials" value="Credentials..." id="credentials" style="border:1px solid;border-color:#B0B0B0;width:225px;padding:4px;margin-left:10px;margin-bottom:10px;margin-top:10px;color: #000;"
onmouseup="format()" ondrop="format()" ondragover="{this.value=''; this.style.color='#000';}" onfocus="if (this.value==this.defaultValue) {this.value=''; this.style.color='#000';}" onblur="if(this.value=='') {this.value=this.defaultValue; this.style.color='#000';}"></div>
<div style="float: left"><input ondblclick="this.value=''" type="text" name="date" value="Date..." id="date" style="border:1px solid;border-color:#B0B0B0;width:225px;padding:4px;margin-left:10px;margin-bottom:10px;margin-top:10px;color: #000;"
onmouseup="format()" ondrop="format()" ondragover="{this.value=''; this.style.color='#000';}" onfocus="if (this.value==this.defaultValue) {this.value=''; this.style.color='#000';}" onblur="if(this.value=='') {this.value=this.defaultValue; this.style.color='#000';}"></div>
<div style="float: left;"><input ondblclick="this.value=''" type="textarea" name="evidence" value="Evidence..." id="evidence" style="border:1px solid;border-color:#B0B0B0;width:225px;padding:4px;margin-left:10px;margin-bottom:10px;margin-top:10px;color: #000;"
onmouseup="format()" ondrop="format()" ondragover="{this.value=''; this.style.color='#000';}" onfocus="if (this.value==this.defaultValue) {this.value=''; this.style.color='#000';}" onblur="if(this.value=='') {this.value=this.defaultValue; this.style.color='#000';}"></div>
<div style="float: left;"><input ondblclick="this.value=''" type="text" name="tagline" value="Tagline..." id="tagline" style="border:1px solid;border-color:#B0B0B0;width:225px;padding:4px;margin-left:10px;margin-bottom:10px;margin-top:10px;color: #000;"
onmouseup="format()" ondrop="format()" ondragover="{this.value=''; this.style.color='#000';}" onfocus="if (this.value==this.defaultValue) {this.value=''; this.style.color='#000';}" onblur="if(this.value=='') {this.value=this.defaultValue; this.style.color='#000';}"></div>
<input class="button" type="reset" value="Clear Form" onClick="clearForm()" style="margin:5px 5px 5px 10px;float:left">
</form>
, 이벤트 리스너 코드는 파이어 폭스에서 작동한다.
변경 이벤트의 문제점은 텍스트 필드가 포커스를 잃어야한다는 것입니다. 나는 그것을 원하지 않는다. 나는 모든 유형의 사용자 입력을 듣고 바로 업데이트 할 수있는 솔루션을 찾고있다. –
사용자가 (아마도) 요소 업데이트를 완료했음을 알 수있는 유일한 시간이므로 변경 이벤트를 사용해야합니다. 제출을 기다릴 필요가 있는지 확인하십시오. 더 빨리 어떻게 알게 되겠습니까? 뭔가를 입력으로 드래그하더라도 계속 진행하기 전에 수정할 수 있습니다. 사용자 유형에 따라 서식을 지정하는 것은 사용하기 힘든 끔찍한 사용 불가 기능입니다. – RobG
사실, 제가하고있는 프로젝트는 웹 사이트가 아니라 확장입니다. 이 양식의 모든 목적은 텍스트 서식을 지정하는 것입니다. 사용자가 최종 결과를 원하기 때문에 제출 또는 이동 버튼의 번거 로움을 없애 실시간으로 업데이트하고 싶습니다. 또한 양식을 제출하지 않고 양식 아래의 contenteditable div에 서식있는 텍스트를 인쇄하므로 사용자는 항상 양식 필드로 되돌아 가서 편집 할 수 있습니다. –