버튼이 하나 뿐인 입력 요소가 2 개 있다고 가정 해 보겠습니다. 버튼 하나의 입력 요소에 대해 한 번에 하나는 현재 초점을 맞추고 있지만 각 요소의 포커스 상태를 캡처하는 방법을 모르겠다.자바 스크립트 : 다른 텍스트 입력에 동일한 버튼을 사용하는 방법은 무엇입니까?
<head>
<script type="text/javascript">
var id_box = document.createElement('input');
id_box.id = 'id_box';
id_box.type = 'text';
div.appendChild(id_box);
var weight_box = document.createElement('input');
weight_box.id = 'weight_box';
weight_box.type = 'text';
div.appendChild(weight_box);
function showLetter() {
if (id_box is being focused){
document.getElementById('id_box').value = 'ABC';
}
if (weight_box is being focused){
document.getElementById('weight_box').value = 'ABC';
}
}
</script>
</head>
<body>
<button onclick="showLetter()">ABC</button>
</body>
어떤 생각 :
이 예제를 고려하시기 바랍니다? 고맙습니다.
두 번째 경우에 getElementById ("weight_box")'...를 사용한다고 가정합니다. ... – 6502
@ 6502 제 코드를 수정 해 주셔서 감사합니다. – Protocole