다른 표 셀의 변경 내용을 기반으로 표 셀을 자동 업데이트하려고합니다. 사용자는 이름, 성 및 사용자 이름을가집니다. 사용자 이름은 첫 번째 성 + 성으로 구성됩니다. 현재 코드는 다음과 같습니다.자바에서 사용자 입력을 기반으로 표 셀 자동 업데이트
<html>
<head>
<script type = "text/javascript">
function updateUsername(){
var firstname = document.getElementById("tdFirstname").firstChild.firstChild.nodeValue;
var lastname = document.getElementById("tdLastname").firstChild.firstChild.nodeValue;
var username = document.getElementById("tdUsername").innerHTML = firstname + lastname;
}
</script>
</head>
<body>
<table id = 'confirm'>
<tr>
<th>Firstname</th>
<td id = 'tdFirstname'>
<div onkeypress = 'updateUsername()' contentEditable>
Johnny
</div>
</td>
</tr>
<tr>
<th>Lastname</th>
<td id = 'tdLastname'>
<div onkeypress = 'updateUsername()' contentEditable>
Sppleseed
</div>
</td>
</tr>
<tr>
<th>Username</th>
<td id = 'tdUsername'>
JSPPLESEED
</td>
</tr>
</table>
</body>
</html>
코드는 작동하지만 (첫 번째 이름과 성을 함께 사용합니다. 새 문자가 입력 된 후 업데이트되지 않습니다. 즉, 앱스 시드로 성을 업데이트하면 (예 : 사용자 이름이 Sppleseed로 유지됨) 한 문자를 변경해도 효과가 없습니다. 그러나 두 번째 키를 누르면 Appleseed로 변경하십시오. 제 코드에 문제가 있습니까? 또는 새로운 글자가 입력/삭제 된 후에 업데이트해야하는 내용을 놓친 것입니까? 이것은 매우 실망 스럽습니다.
Genious! 지금 멋진 작품! – Vince