我想通过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