爲什麼此代碼不能正確工作?如果某人選擇了ID爲「1599」的東西,則提醒將顯示「$ 1,599.00」。如果ID不匹配,那麼警報應顯示「$ 1,499.00」。但事實並非如此。有人能幫我解決這個問題嗎?其他語句中的警報
感謝
<html>
<script type="text/javascript">
function showPrice(){
var a = document.getElementById();
if (a == "1599"){
alert("$1,599.00");
}
else {
alert("$1,499.00");
}
}
<body>
<div class="hc_right">
<input type="button" class="spc" value="Price" onclick="showPrice()" />
<p class="price" id="1599">$1,599.00</p>
</div>
<div class="hc_right">
<input type="button" class="spc" value="Price" onclick="showPrice()" />
<p class="price" id="1499">$1,499.00</p>
</div>
</div>
</body>
</html>
你對這個調用有什麼期望:'a = document.getElementById();'? – 2011-05-27 02:18:29