Foros del Web » Programando para Internet » Javascript »

Calendario en Javascript

Estas en el tema de Calendario en Javascript en el foro de Javascript en Foros del Web. Saludos; A traves de una pagina consegui este calendario que estoy utilizando, pero tengo un pequeño problema, cuando es el ultimo dia de mes me ...
  #1 (permalink)  
Antiguo 31/05/2010, 05:16
 
Fecha de Ingreso: diciembre-2007
Ubicación: Ibiza
Mensajes: 37
Antigüedad: 16 años, 3 meses
Puntos: 0
Calendario en Javascript

Saludos;

A traves de una pagina consegui este calendario que estoy utilizando, pero tengo un pequeño problema, cuando es el ultimo dia de mes me marca toda la fila y yo solo quiero que me marque la casilla del dia actual, he estado probando pero no se como hacerlo, si alguien me puede ayudar os lo agradecria un monton!!!

aqui os dejo el codigo entero;

Código Javascript:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script type="text/javascript">
  5. /**************************************************************
  6. Calendario con selector. Script creado por Tunait! (8/8/2004) Actualizado el 28-Ene.-07
  7. Script de libre uso con la condición de que permanezcan intactas estas líneas, osea, los créditos.
  8. Distribución no autorizada en sitios de script sin previa autorización
  9. Ver condiciones de uso en http://javascript.tunait.com/
  10. ****************************************************************/
  11.  
  12. var idContenedor = "miCalendario"
  13.  
  14. var hoy = new Date()
  15. var mes = hoy.getMonth()
  16. var dia = 1
  17. var anio = hoy.getFullYear()
  18. var diasSemana = new Array ('L','M','M','J','V','S','D')
  19. var meses = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre')
  20.  
  21. var tunIex=navigator.appName=="Mozilla Firefox"?true:false;
  22. if(tunIex && navigator.userAgent.indexOf('Opera')>=0){tunIex = false}
  23. tunOp = navigator.userAgent.indexOf('Opera')>=0 ? true: false;
  24. function tunCalendario(){
  25.     dia2 = dia
  26.     tab = document.createElement('table')
  27.     tab.id = 'calendario'
  28.     document.getElementById(idContenedor).appendChild(tab)
  29.     tcabeza = document.createElement('thead')
  30.     tab.appendChild(tcabeza)
  31.     fi2 = document.createElement('tr')
  32.     fi2b = document.createElement('th')
  33.     fi2b.colSpan = 7
  34.     fi2.id = 'mesCalendario'
  35.     fi2b.appendChild(document.createTextNode(meses[mes] + "  -  " + anio))
  36.     fi2.appendChild(fi2b)
  37.     tcabeza.appendChild(fi2)
  38.     fi = document.createElement('tr')
  39.     tcabeza.appendChild(fi)
  40.     for(m=0;m<7;m++){
  41.         ce = document.createElement('th')
  42.         ce.appendChild(document.createTextNode(diasSemana[m]))
  43.         fi.appendChild(ce)
  44.         if(m == 6){ce.style.marginRight = 0}
  45.         }
  46.         var escribe = false
  47.         var escribe2 = true
  48.     fecha = new Date(anio,mes,dia)
  49.     var d = fecha.getDay()-1 //dia semana
  50.     if(d<0){d = 6}
  51.     tcuerpo = document.createElement('tbody')
  52.     tab.appendChild(tcuerpo)
  53.     while(escribe2){
  54.         fi = document.createElement('tr')
  55.         co = 0
  56.         for(t=0;t<7;t++){
  57.             ce = document.createElement('td')
  58.             if(escribe && escribe2){
  59.             fecha2 = new Date(anio,mes,dia)
  60.            
  61.                 if(fecha2.getMonth() != mes){escribe2 = false;}
  62.                 else{ce.appendChild(document.createTextNode(dia));dia++;co++}
  63.             }
  64.             if(d == t && !escribe){
  65.             ce.appendChild(document.createTextNode(dia))
  66.             dia++;co++
  67.             escribe = true
  68.             }
  69.             fi.appendChild(ce)
  70.             if(hoy.getDate()+1 == dia && mes == hoy.getMonth() && anio == hoy.getFullYear()){ce.className = "Hoy"}
  71.             }
  72.            
  73.         if(co>0){tcuerpo.appendChild(fi)}
  74.        
  75.         }
  76.     dia = dia2
  77. }
  78. function borra(){
  79. document.getElementById(idContenedor).removeChild(document.getElementById('calendario'))
  80. }
  81. function establecerFecha(){
  82. tunFe = new Date()
  83. document.getElementById('tunMes').options[tunFe.getMonth()].selected = true
  84. document.getElementById('tunAnio').value = tunFe.getFullYear()
  85. }
  86. function mostrarContenido(){
  87. document.getElementById('contenido').style.visibility="visible";
  88. }
  89. function ocultarContenido(){
  90. document.getElementById('contenido').style.visibility="hidden";
  91. }
  92. </script>
  93. <style type="text/css">
  94.  
  95. #calendario{
  96.     font-family: Tahoma, Arial, Helvetica, sans-serif;
  97.     font-size: 12px;
  98.     text-align: center;
  99.     margin-left: auto;
  100.     margin-right: auto;
  101.     border-collapse: collapse;
  102.     border-right: 2px solid #999999;
  103.     border-bottom: 2px solid #999999;
  104. }
  105.  
  106. /*#mesCalendario para configurar aspectos de la caja que muestra el mes y el año*/
  107. #mesCalendario{
  108.     font-weight: bold;
  109.     text-align: center;
  110.     color: #CC6633;
  111.     background-color: #E4CAAF;
  112.  
  113. }
  114. #calendario th, #calendario td{
  115.     border: 1px solid #999999;
  116.     padding: 3px;
  117.     font-size: 110%;
  118. }
  119. #calendario th{
  120.     color: #CC6633;
  121. }
  122. /*.Hoy para configurar aspectos de la caja que muestra el día actual*/
  123. .Hoy{
  124.     color: #990000;
  125.     font-weight: bold;
  126.     cursor:pointer;
  127.     background-repeat: no-repeat;
  128.     background-color: #AEAEFF;*/
  129. }
  130. .capa_borde {
  131.     border: 1px solid #000000;
  132.     position: absolute;
  133. }
  134. #miCalendario{
  135.     position: absolute;
  136.     height: 198px;
  137.     width: 187px;
  138.     border-top-style: none;
  139.     border-right-style: none;
  140.     border-bottom-style: none;
  141.     border-left-style: none;
  142.     left: 27px;
  143.     top: 103px;
  144.     visibility: visible;
  145.     z-index: 2;
  146. }
  147. /*.selectores para configurar aspectos de los campos para el mes y el año*/
  148. .selectores{
  149.     font-family: verdana;
  150.     font-size: 12px;
  151.     color: #990000;
  152.     margin-bottom: 2px;
  153. }
  154.  
  155. #contenido {
  156.     position:absolute;
  157.     left:28px;
  158.     width:232px;
  159.     height:73px;
  160.     z-index:4;
  161.     top: 4px;
  162.     visibility: hidden;
  163. }
  164. #selectores {
  165.     position:absolute;
  166.     left:17px;
  167.     top:81px;
  168.     width:208px;
  169.     height:28px;
  170.     z-index:5;
  171. }
  172. #capa_borde {
  173.     position:absolute;
  174.     left:23px;
  175.     top:67px;
  176.     width:194px;
  177.     height:235px;
  178.     z-index:1;
  179. }
  180. #cerrar {
  181.     position:absolute;
  182.     left:190px;
  183.     top:65px;
  184.     width:41px;
  185.     height:22px;
  186.     z-index:3;
  187. }
  188. </style>
  189. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  190. <title>Documento sin t&iacute;tulo</title>
  191. </head>
  192.  
  193. <body onload="tunCalendario();establecerFecha()" >
  194. <div id="miCalendario" onclick="mostrarContenido()"></div>
  195. <div id="contenido"><div id="cerrar" onClick="ocultarContenido()"><img src="imagenes/gif/cerrar3.gif" alt="cerrar" width="40" height="20" /></div>
  196.   <table width="249" height="73" border="0" cellpadding="0" cellspacing="0">
  197.     <tr>
  198.       <td width="231"><img src="imagenes/gif/boc_calendario.gif" alt="contenido" width="230" height="103" /></td>
  199.     </tr>
  200.   </table>
  201. </div>
  202. <div id="selectores">
  203. <div align="center">
  204.     <select name="select" class="selectores" id="tunMes" onchange="mes=this.selectedIndex;borra();tunCalendario()">
  205.       <option value="0">Enero</option>
  206.       <option value="1">Febrero</option>
  207.       <option value="2">Marzo</option>
  208.       <option value="3">Abril</option>
  209.       <option value="4">Mayo</option>
  210.       <option value="5">Junio</option>
  211.       <option value="6">Julio</option>
  212.       <option value="7">Agosto</option>
  213.       <option value="8">Septiembre</option>
  214.       <option value="9">Octubre</option>
  215.       <option value="10">Noviembre</option>
  216.       <option value="11">Diciembre</option>
  217.     </select>
  218.    
  219.     <select name="select" class="selectores" id="tunAnio" onchange="if(!isNaN(this.value)){anio=this.value;borra();tunCalendario()}">
  220.       <option value="2010">2010</option>
  221.       <option value="2011">2011</option>
  222.       <option value="2012">2012</option>
  223.       <option value="2013">2013</option>
  224.       <option value="2014">2014</option>
  225.       <option value="2015">2015</option>
  226.       <option value="2016">2016</option>
  227.       <option value="2017">2017</option>
  228.       <option value="2018">2018</option>
  229.       <option value="2019">2019</option>
  230.       <option value="2020">2020</option>
  231.     </select>
  232.   </div>
  233. </div>
  234. <div class="capa_borde" id="capa_borde"></div>
  235.  
  236. </body>
  237. </html>

Etiquetas: calendario
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:30.