首页 > 其他 > 详细

script中获取不到元素id

时间:2016-12-11 15:20:14      阅读:270      评论:0      收藏:0      [点我收藏+]

<head>
<script type="text/javascript">

function getchange(){
var date = new Date();
var sec = date.getSeconds();
var spanNode = document.getElementById("time");
spanNode.innerHTML=sec;

}
getchange();  //在这里调用函数,会出现找不到spannode的情况  解决办法是 在body中写加上onload =ready(),或者,script写在body下面。然而使用window。setinterval(调用functions)时候,无论script放在哪里都可行。
window.setInterval("getchange()",1000);


</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body >
当前系统时间:<span id="time"></span>
</body>

</html>

script中获取不到元素id

原文:http://www.cnblogs.com/lyjmatrix/p/6159596.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!