Показать сообщение отдельно
  #3 (permalink)  
Старый 30.06.2016, 17:10
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,072

piraids,
<!DOCTYPE html>
<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  <script>
$(function() {
    jQuery.fn.digitalWatch = function() {
        function formatTime(num)
      {
         return ("0" + num).substr(-2)
      }
        this.each(function(i, el) {
            var el = $(el),
                init = function() {
                    var date = new Date,
                        hours = date.getHours(),
                        minutes = date.getMinutes(),
                        seconds = date.getSeconds();
                    hours = formatTime(hours);
                    minutes = formatTime(minutes);
                    seconds = formatTime(seconds);
                    el.html(hours + ":" + minutes + ":" + seconds);
                    setTimeout(init, 1000)
                };
            init()
        });
        return this
    };
    $(".clock").digitalWatch().css({
        color: "red"
    })
});
  </script>
</head>

<body>
<div class="clock"></div> <div class="clock"></div>
</body>
</html>
Ответить с цитированием