U
U
underwater2017-10-19 13:27:25
JavaScript
underwater, 2017-10-19 13:27:25

Adding date and time to project?

I'm just starting to deal with js, the experience is almost zero, I added a script to the project to call the date and time

(function () {

  window.isimple=window.isimple || {}
  window.isimple.dates=window.isimple.dates || {}
  window.isimple.dates.getCurrentDate=function () {
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1;
    var curr_year = d.getFullYear();

    return (curr_year + "." + curr_month + "." + curr_date);
  }
    window.isimple.dates.getCurrentTime=function () {
      var d = new Date();
      var curr_hours = d.getHours();
      var curr_minutes = d.getMinutes();

      return (curr_hours + ":" + curr_minutes);
    }
})();

and I call it in the zulnik like this,
<label value="isimple.dates.getCurrentDate()"/>
but the label code itself is displayed, what is the problem, tell me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Nameless08, 2017-10-19
@dyfran

I think you should do it like this:

<label id="labelOne" for=""></label>
<label id="labelTwo" for=""></label>

'use strict';

    ;(function () {

      var labelOne = document.getElementById('labelOne'),
          labelTwo = document.getElementById('labelTwo');

      

      window.isimple=window.isimple || {};
      window.isimple.dates=window.isimple.dates || {};
      
      window.isimple.dates.getCurrentDate=function () {
        var d = new Date();
        var curr_date = d.getDate();
        var curr_month = d.getMonth() + 1;
        var curr_year = d.getFullYear();

        return (curr_year + "." + curr_month + "." + curr_date);
      }

      labelOne.innerHTML =  window.isimple.dates.getCurrentDate();

      window.isimple.dates.getCurrentTime=function () {
          var d = new Date();
          var curr_hours = d.getHours();
          var curr_minutes = d.getMinutes();

          return (curr_hours + ":" + curr_minutes);
      }

      labelTwo.innerHTML =  window.isimple.dates.getCurrentTime();

    })();

You can, in principle, stick into one label, a matter of technology.

V
Vasily Petrov, 2017-10-19
@ratha

native js can't bind directly to html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question