<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Switch/Case handling</title>
<!--<script src="js/switch.js"></script>-->
<script>
window.onload=initAll;
function initAll(){
document.getElementById("cat").onclick=saysomething;
document.getElementById("dog").onclick=saysomething;
document.getElementById("tiger").onclick=saysomething;
}
function saysomething(){
/*alert("init");*/
switch(this.id){
case "cat":
alert("I am a cat");
break;
case "dog":
alert("I am a dog");
break;
case "tiger":
alert("I am a tiger");
break;
default:
}
}
</script>
</head>
<body>
<form action="#">
<input type="button" id="cat" value="cat">
<input type="button" id="dog" value="dog">
<input type="button" id="tiger" value="tiger">
</form>
</body>
</html>
js中getElementById()的用法
最新推荐文章于 2023-11-03 10:06:08 发布