Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

<script type="text/javascript">
        var int= setInterval(clock(),100);
        function clock(){
            var time = new Date();
            document.getElementsById("clock").value = time;

        }
    </script>
</head>
<body>
    <input type="text" id="clock" size="50" />
</body>

在input里每100毫秒的频率显示当前时间,可是document.getElementsById("clock").value = time;怎么也不能value的input

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
160 views
Welcome To Ask or Share your Answers For Others

1 Answer

你这问题多的啊..

 setInterval你直接传入了clock(),改为clock
 document.getElementsById("clock")注意没有s,是getElementById
 script里面用window.onload包裹一下或者直接加到input标签的后面
 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...