javascript - How To Make A Default Text Display For This Script? -
i'm using script display current date someone, want 2 things it.
first, want change format mm/dd/yy, it's showing year in 2 digits.
then second, how can add default? if it's not able pulled someone, show "today" instead of date?
here's script if help:
var currenttime = new date() var month = currenttime.getmonth() + 1 var day = currenttime.getdate() var year = currenttime.getfullyear() document.write(month + "/" + day + "/" + year)
add div html , put default text inside it:
<div id="date">today</div>
then javascript, change it, , if user don't have javascript, remains not changed:
// create date var currenttime = new date(); var month = currenttime.getmonth() + 1; var day = currenttime.getdate(); var year = currenttime.getfullyear(); var date = month + "/" + day + "/" + (year + '').substring(2); // insert document.getelementbyid('date').innerhtml = date;
[!]
don't forget add js after element or add document ready.
Comments
Post a Comment