Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    semplice link ai numeri del calendario

    Gentile team, ho la necessità di aggiungere ai numeri generati da questo calendario , un link che punta ad una pagina con il valore della data richiesta

    Codice PHP:
    <script language="JavaScript" type="text/javascript">
    var 
    day=1
    var x=1
    var primariga=true
    var giorning=new Array("","Mon","Tue","Wed","Thu","Fry","Sat","Sun")
    var 
    data=new Date()
    var 
    lunghezzemesi=new Array(31,28,31,30,31,30,31,31,30,31,30,31)
    data.setDate(1)
    primogiorno=data.toGMTString()
    primogiorno=primogiorno.substring(0,3)
    document.write("<table width=\"200px\" border=\"0\"><tr>")
    document.write("<th>Lun<\/th><th>Mar<\/th><th>Mer<\/th><th>Gio<\/th><th>Ven<\/th><th>Sab<\/th><th>Dom<\/th><\/tr><tr>")
    for (
    i=1;day<=lunghezzemesi[data.getMonth()];i++) {
        if (
    day==new Date().getDate()) {
            
    giorno="[b]"+day+"<\/b>";
        }
        else {
            
    giorno=day;
        }
        if (
    primariga) {
            if (
    giorning[i]!=primogiorno) {
                if (
    x<7) {
                    
    document.write("<td><\/td>")
                    
    x++
                }
                else {
                    
    document.write("<td><\/td><\/tr><tr>")
                    
    x=1
                
    }
            }
            else {
                
    primariga=false
                
    if (x<7) {
                    
    document.write("<td><a",giorno,"<\/td>")
                    
    x++
                }
                else {
                    
    document.write("<td>",giorno,"<\/td><\/tr><tr>")
                    
    x=1
                
    }
            }
            
    day++
        }
        else {
            if (
    x<7) {
                
    document.write("<td>",giorno,"<\/td>")
                
    x++
            }
            else {
                
    document.write("<td>",giorno,"<\/td><\/tr><tr>")
                
    x=1
            
    }
            
    day++
        }
    }

    for (
    i=0;i<=(7-x);i++) {
        
    document.write("<td><\/td>")
    }
    document.write("<\/tr><\/table")
    </script>

    e al click del numero dovrei passare questo link di esempio

    data.php?data=20121106

    sapreste aiutarmi?
    ( anche se avete altri calendari da suggerirmi )

    grazie mille :ciauz: 
    L'intuizione creativa più di ogni altra cosa è l'unico elemento per cui la vita vale la pena di essere vissuta (D.W)

  2. #2
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Vedi se questo va bene, altrimenti cerca in rete ritengo che troverai (con un po d'impegno) sicuramente quello che fa per te
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  3. #3
    Utente di HTML.it L'avatar di carlomarx
    Registrato dal
    Oct 2009
    Messaggi
    1,669
    Cominciamo con le semplificazioni. Lo script che hai postato tu si può notevolmente semplificare così:

    codice:
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Esempio</title>
    <script type="text/javascript">
    function appendCalendar () {
    
    	var
    		oTD, oTH = document.createElement("tr"), oTBody = document.createElement("tbody"),
    		oTHead = document.createElement("thead"), oTable = document.createElement("table"),
    		nIter = 0, oMonthStart = new Date(), aMonthsLen = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
    		aDaysNames = ["Lun", "Mar", "Mer", "Gio", "Ven", "Sab", "Dom"];
    
    	for (nIter; nIter < 7; nIter++) {
    		oTD = document.createElement("th");
    		oTD.innerHTML = aDaysNames[nIter];
    		oTH.appendChild(oTD);
    	}
    
    	oTHead.appendChild(oTH);
    	oMonthStart.setDate(1);
    	nIter = 0;
    
    	for (var nEndBlanks = (oMonthStart.getDay() + 6) % 7, nEnd = aMonthsLen[oMonthStart.getMonth()] + nEndBlanks, nTotal = nEnd + ((7 - nEnd % 7) % 7); nIter < nTotal; nIter++) {
    		if (nIter % 7 === 0) {
    			oTH = document.createElement("tr");
    			oTBody.appendChild(oTH);
    		}
    		oTD = document.createElement("td");
    		oTD.innerHTML = nIter < nEndBlanks || nIter + 1 > nEnd ? "" : nIter - nEndBlanks + 1;
    		oTH.appendChild(oTD);
    	}
    
    	oTable.appendChild(oTHead);
    	oTable.appendChild(oTBody);
    	document.getElementById("calendar").appendChild(oTable);
    
    }
    </script>
    
    </head>
    
    <body onload="appendCalendar();">
    
    <div id="calendar"></div>
    
    </body>
    </html>
    Detto questo, per ottenere quello che vuoi potresti fare così:

    codice:
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Esempio</title>
    <script type="text/javascript">
    function appendCalendar () {
    
    	var
    		oTD, oTH = document.createElement("tr"), oTBody = document.createElement("tbody"),
    		oTHead = document.createElement("thead"), oTable = document.createElement("table"),
    		nIter = 0, oMonthStart = new Date(), aMonthsLen = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
    		aDaysNames = ["Lun", "Mar", "Mer", "Gio", "Ven", "Sab", "Dom"];
    
    	for (nIter; nIter < 7; nIter++) {
    		oTD = document.createElement("th");
    		oTD.innerHTML = aDaysNames[nIter];
    		oTH.appendChild(oTD);
    	}
    
    	oTHead.appendChild(oTH);
    	oMonthStart.setDate(1);
    	nIter = 0;
    	
    	for (var nDay, nEndBlanks = (oMonthStart.getDay() + 6) % 7, nEnd = aMonthsLen[oMonthStart.getMonth()] + nEndBlanks, nTotal = nEnd + ((7 - nEnd % 7) % 7); nIter < nTotal; nIter++) {
    		if (nIter % 7 === 0) {
    			oTH = document.createElement("tr");
    			oTBody.appendChild(oTH);
    		}
    
    		oTD = document.createElement("td");
    		nDay = nIter - nEndBlanks + 1;
    
    		oTD.innerHTML = nIter < nEndBlanks || nIter + 1 > nEnd ?
    			""
    			: "<a href=\"data.php?data=" + oMonthStart.getFullYear() + oMonthStart.getMonth() + (nDay / 100).toFixed(2).substr(-2) + "\">" + nDay + "<\/a>";
    
    		oTH.appendChild(oTD);
    	}
    
    	oTable.appendChild(oTHead);
    	oTable.appendChild(oTBody);
    	document.getElementById("calendar").appendChild(oTable);
    
    }
    </script>
    
    </head>
    
    <body onload="appendCalendar();">
    
    <div id="calendar"></div>
    
    </body>
    </html>
    Tutto ciò che fai con jQuery puoi farlo meglio e con la metà del codice in puro JavaScript.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.