我想通過JavaScript「if」例程更改div樣式的背景顏色,無法得到錯誤消息:「Uncaught TypeError:無法設置屬性'className'爲null」Javascript和「div」標籤
<head>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<style type="text/css">
.ok{ background-color:green; }
.dead{ background-color:red; }
</style>
<script type="text/javascript">
function emea(){
if (<?php echo $variable;?>==1) {
document.getElementById('test').className = 'ok';
}
else {
document.getElementById('test').className = 'dead';
}
}
emea();
</script>
</head>
<div id="test">BlaBla</div>
_javascript_,不_JAVA script_。它與java無關。 – BackSlash 2014-11-05 14:49:25
*我想通過javascript「if」例程更改div樣式的背景顏色:*確定。有什麼問題? – Compass 2014-11-05 14:51:39
爲什麼打開PHP標籤? – 2014-11-05 14:51:46