0
왜이 코드가 제대로 작동하지 않습니까?Img onkeydown이 작동하지 않습니다.
<img src="picture.jpg" id="picture"/>
<script>
document.getElementById('picture').onkeydown = function() {alert('tekst');}
</script>
왜이 코드가 제대로 작동하지 않습니까?Img onkeydown이 작동하지 않습니다.
<img src="picture.jpg" id="picture"/>
<script>
document.getElementById('picture').onkeydown = function() {alert('tekst');}
</script>
이미지에 포커스가 없으므로 'onkeydown'이벤트를 수신하지 않습니다. onkeydown 이벤트가 작동하도록 이미지 포커스를 줄 수 있는지 확실하지 않습니다.
대신 초점을 가질 수있는 a 태그 안에 이미지를 배치 할 수 있으므로 onkeydown 이벤트를들을 수 있습니다. 이 같은
뭔가 :
<a id="picture" href="#">
<img src="picture.jpg" />
</a>
<script>
// The a tag
var picture = document.getElementById('picture');
// You have to put focus on the atag (or any element that you want to have for you onkeydown event.
picture.focus();
// Now your event will work
picture.onkeydown = function() {
alert('tekst');
}
</script>
검사 목록 : 이 기능이 결합되어 있습니까? 이벤트가 생성 되었습니까? 이벤트 핸들러가 호출 되었습니까? – Prasanth
나는'keydown '(예 :'39')에 대해 더 많이 말해야한다고 생각합니다. – Raza