我試圖在它裏面的圖像上單擊作爲代碼時提醒div的id爲:如何使用javascript獲取html元素ID?
<html>
<head>
<style type="text/css">
.test1{
width:500px;
background: #cc0000;
color:#fff;
height:200px;
margin:0px auto;
}
</style>
<script>
function hidediv(){
var a = document.getElementById("divtobehide");
alert(a);
}
</script>
</head>
<body>
<div id="divtobehide" class="test1">
This is the div to be hiddenite
<img src="index.jpg" id="imgid" onclick="hidediv()" style="float:right;">
</div>
</body>
這裏出現的警告框,但不顯示的ID。如何解決這個問題?
他需要警報箱爲什麼你這樣做? –
只是覺得他只是在提醒這個ID作爲調試,因爲其他方面沒有什麼好處。 – Kzqai