Urmatorul script afiseaza data completa si ora, ca in exemplu de mai jos
Pentru a adauga acest script intr-o pagina web:
1. Introduceti in sectiunea HEAD a documentul HTML, urmatorul script:
<script type="text/javascript">
// Creaza matricele cu zilele saptamanii si lunile anului
var ziarray=new Array("Duminica", "Luni", "Marti", "Miercuri", "Joi", "Vineri", "Sambata")
var lunaarray=new Array("Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie", "Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decemberie")
// Functia care preia datele (an, luna, zi, ora)
function datacom() {
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12) {
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
// Aici poti modifica marime si tipul fontului
var cdate="<small><font color='#fefefe' face='Arial'><b>"+ziarray[day]+", "+daym+" "+lunaarray[month]+" "+year+"<br> Ora: "+hours+":"+minutes+":"+seconds+" "+dn
+"</b></font></small>"
// Afiseaza datele in elementul HTML cu id=dataora
document.getElementById("dataora").innerHTML=cdate
}
// Daca elementul HTML cu id=dataora exista
// Executa functia datacom() la fiecare secunda
function arata() {
if (document.getElementById("dataora"))
setInterval("datacom()",1000)
}
window.onload=arata;
</script>
<div style="width:200px; background-color:#0101fe; text-align:center" id="dataora"></div>
Prima linie ...<br> Alta linie...
#id { letter-spacing: 2px; }
var elm = document.getElementById("theID"); var content = elm.innerHTML; alert(content);
echo "Adresa URL: http://CoursesWeb.net";
She does not paint that landscape. - Ea nu picteaza acel peisaj.
Ella no canta esa canciĆ³n. - Ea nu canta acel cantec.