El lado del servidor incluye:
Los programadores experimentados de JavaScript saben que la reutilización de código es buena. Los programadores experimentados de JavaScript también saben que las funciones de JavaScript son tipos de datos.
Entonces, deberíamos poder almacenar una función JavaScript dentro de una variable de sesión o una variable de aplicación, ¿verdad? Desafortunadamente, no. La forma de reutilizar las funciones de JavaScript en muchas páginas es usar SSI: el lado del servidor incluye.
<%@Language = "javascript"%> <html> <adead> <!-#include file = "script13a.asp"-> <title> <%respuesta.write (whatTimeSit ())%> </title> </bead> <body> <%Response.write ("La fecha y la hora son" + Detetime + "<br> <br> /r")Response. "<br> <br> /r")Response.write("Tomorrow será un" + finddayofweek (mañana) + "/r")%> </body> </html>Haga clic aquí para ejecutar el script en una nueva ventana.
Mire el código para script13.asp. Llama a un archivo de inclusión a través de esta línea:
<html> <foad> <title> 10:57:20 AM </title> </head> <body> La fecha y la hora son el 4/11/2003 10:57:20 am <br> <br> La fecha del mañana es el 4/12/2003 <br> <br> Mañana será un sábado </fody> </html>
El código HTML final se ve tan bien y simple. Nunca sabrías que el objeto Date () se había derribado y volvido a armar. A continuación se muestra el archivo de inclusión.
<%function whatTimeSit () {var m = new Date () var minucin = m.getmines () var Second = m.getSeconds () var ampm = falseif (minuto> = 0 && minuto <10) {minuto = ("0" + minuto)} if (segundo> = 0 && Second <10) {segundo = ("0" + segundo)} var horas = m.gethours () if ((horas> 12) {ampm = trueHours = Hours-12} if (Hours == 12) {ampm = true} if (horas == 0) {horas = horas + 12ampm = false} if (ampm) {ampm = "pm" Date (); var mes = (dateTime.getMonth () + 1) + "/"; var day = datTime.getDate () + "/"; var año = datTime.getblyaryear (); var datetime = mes + day + año + "" + whatTimeSit (); var mañana = nueva fecha () mañana Mañana.getDate () + "/" año = mañana.getblyear () mañana = mes + día + año Finddayofweek (dateInquestion) {// Formatear para DateCestion es mm/dd/yyyy o m/d/yyyy // y supone que los/'s son son presente.myregExp = // d {1,2} /// mymonth = (parseInt (dateInquestion.match (myregExp)) -1) myregexp = //// d {1,2} /// myday = new String (dateInquestion.match (myRegExp)) myday = parseint (myday.substring (1, 1, my, mylhong.match (myregexp)) myday = parseint (myday.substring (1, myQuestion.match (myregexp)) myday = parseint (myday.substring (1, 1, mylhong.math (myRegexp)) myday = parseint (myday.substring (1, 1, mylhong.lengh) ) myregExp = //// d {4}/myyear = new String (dateInquestion.match (myregexp)) myyear = parseint (myyear.substring (1, myyear.length)) dateInQueste = new Date (myyear, mymonth, myday) dayofeek = newek Arraydayofweek [0] = "domingo" dayofweek [1] = "lunes" dayofweek [2] = "martes" dayofweek [3] = "miércoles" dayofweek [4] = "jueves" dayofweek [5] = "viernes" dayofweek [6] = "sábado" dayofweek = dayofweek [dateinquestion.getgetday () de regreso;