<html>
<head>
<script type="text/javascript">
(function() {
alert("here.....");
var ss = document.getElementById("cc").value;
alert("xxxxx= "+ss);
})()
</script>
</head>
<body>
<input type="checkbox" id = "cc" name="c" onclick="getit();" onmouseover="mouseover();" disabled>
</body>
<html>
因为DOM没有加载完成, 无法读取 value
.
解决方法:
-
script
标签放底部 - 使用 jQuery
ready()
- 挂载到
onload
事件
DEMO:
<html>
<head>
<script>
alert("here.....");
window.onload = function() {
var a = document.getElementById("cc").value;
alert("xxxxx= "+a);
}
</script>
</head>
<body>
<input type="checkbox" id="cc">
</body>
<html>