close
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
span{
color: darkRed;
}
#container{
cursor: pointer;
}
</style>
</head>
<body>
<div id="container">
<img src="https://api.fnkr.net/testimg/50x50/00CED1/FFF/?text=img+placeholder">
<h2>我是文字</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores neque, cum deserunt. Sed tempore veritatis impedit vero, odio qui unde!</p>
<input type="text" name="">
<a href="http://www.google.com" id="a">我是連結但我按了沒反應喔</a>
</div>
<h2>nodeName顯示<span id="result"></span></h2>
<h2>parentNode顯示<span id="result2"></span></h2>
<script type="text/javascript">
document.getElementById('container').onclick=function(e){
document.getElementById('result').innerHTML=e.target.nodeName;
document.getElementById('result2').innerHTML=e.target.parentNode;
}
document.getElementById('a').onclick=function(e){
e.preventDefault();
}
</script>
</body>
</html>
全站熱搜
留言列表