[英]Uncaught Type Error: Undefined is not a function
HTML Code HTML代码
<table border="0px" id="map-flags" align="center">
<tr><td><img src="flags/ug.jpeg" alt="Welcome" width="160px" height="160px"></td></tr>
</table>
Javascript Code JavaScript代码
<script>
document.getElementbyId('tuts').addEventListener('click', function(e){
console.log(e.toElement.alt);
});
</script>
Am trying to print out the Id in the Console but it brings this error, What could be the problem? 我正在尝试在控制台中打印出ID,但它带来了此错误,可能是什么问题?
Add an ID 添加一个ID
<table border="0px" id="map-flags" align="center">
<tr>
<td>
<img id="tuts" src="flags/ug.jpeg" alt="Welcome" width="160px" height="160px">
</td>
</tr>
</table>
and change getElementbyId to getElement**B**yId 并将getElementbyId更改为getElement ** B ** yId
<script>
document.getElementById('tuts').addEventListener('click', function(){
console.log(this.alt);
});
</script>
**Edit: Change console.log(e.toElement.alt); **编辑:更改console.log(e.toElement.alt); to console.log(this.alt); 到console.log(this.alt); ** **
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.