setInterval函数不起作用

用户名

我正在用jQuery进行本地时间监视。我写了一些代码,但是没有用。这是我的代码:

$(document).ready(function(){
    function addZero(i) {
        if (i <= 9) {
            i = "0" + i;
        }
       return i;
    }
    var d = setInterval(function(){
        var z = new Date();
        var h = addZero(z.getHours());
        var m = addZero(z.getMinutes());
        var s = addZero(z.getSeconds();
        var a = '';
        if (h > 11 ) a = "PM" 
        else a = "AM"
        if (h == 16) h = '0'+4
        $('pre').html(h + ":" + m + ":" + s + "&nbsp;" + "a");
    },1000);
});
阿比舍克·潘迪(Abhishek Pandey)

您犯了一些错误-检查代码

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
  var d,z,h,m,s,a
  function addZero(i) {
    if (i <= 9) i = "0" + i;
    return i;
  }
  d = setInterval( function(){
    z = new Date();
    h = addZero(z.getHours());
    m = addZero(z.getMinutes());
    s = addZero(z.getSeconds());
    a = '';
    if (h > 11 ) a = "PM" 
    else a = "AM"
    if (h == 16) h = '0'+4
    $('#timer').html(h + ":" + m + ":" + s + "&nbsp;" + a);
  },1000);
});
</script>
<pre id="timer"></pre>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章