0
<script type="text/javascript">
//window.onload = Now;
function Now(){
var n=new Date();
return n.toLocaleDateString();

};


</script>

i put the above code in the head part.

<body onload="Now();">

but on the page, there is no show anything.when i using window.onload = Now or put the script code after the label; the result is the same, why?

ps:i want to write the result out on the page. but when i used document.write(Now()); it still not displayed on the page.

stack2013a
  • 29
  • 1
  • 5

3 Answers3

0

You aren't doing anything with the return value of Now(), so it is being quietly discarded.

Perhaps you want to do something like onload="alert(Now());"

Niet the Dark Absol
  • 301,028
  • 70
  • 427
  • 540
0

Try to put alert box. If it exists in the script or not.

Pirates
  • 160
  • 1
  • 8
0

Modify your HTML a bit to have a DOM element that will help you post the resut onto your page,

<body onload="Now();">
    <span id="dateHelper"></span>
</body>

And then modify your script to do the following,

function Now(){
    var n=new Date();
    var lds = n.toLocaleDateString();

    document.getElementById("dateHelper").innerHTML = lds;
};

Test Link

painotpi
  • 6,479
  • 1
  • 32
  • 64