<html>

    <head>
        <script>
            function data() {
                var today = new Date();

                var month = new Array();
                month[0] = "January";
                month[1] = "February";
                month[2] = "March";
                month[3] = "April";
                month[4] = "May";
                month[5] = "June";
                month[6] = "July";
                month[7] = "August";
                month[8] = "September";
                month[9] = "October";
                month[10] = "November";
                month[11] = "December";


                var d = today.getDate();
                var m = month[today.getMonth()];
                var y = today.getFullYear();


            }
        </script>
    </head>

    <body onload="data();">
        <select id="day">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
            <option value="8">8</option>
            <option value="9">9</option>
            <option value="10">10</option>
            <option value="11">11</option>
            <option value="12">12</option>
            <option value="13">13</option>
            <option value="14">14</option>
            <option value="15">15</option>
            <option value="16">16</option>
            <option value="17">17</option>
            <option value="18">18</option>
            <option value="19">19</option>
            <option value="20">20</option>
        </select>
        <select id="month">
            <option value="Jan">Jan</option>
            <option value="Feb">Feb</option>
            <option value="Mar">Mar</option>
            <option value="Apr">Apr</option>
            <option value="May">May</option>
            <option value="Jun">Jun</option>
            <option value="Jul">Jul</option>
            <option value="Aug">Aug</option>
            <option value="Sep">Sep</option>
            <option value="Oct">Oct</option>
            <option value="Nov">Nov</option>
            <option value="Dec">Dec</option>
        </select>
        <select id="year">
            <option value="2014">2014</option>
            <option value="2015">2015</option>
        </select>
    </body>

</html>

Chcę, aby datę wybrać 14 sierpnia 2014 r. Pomoc w części Javaskipt, dane powinny pozostać statyczne (wybrane listy pozostaną statyczne) tylko javascript zostanie zmodyfikowany. Mam trudności z wykonywaniem następnej daty wybranej z rozwijanej Dostępne.

0
user2094357 13 sierpień 2014, 22:33

1 odpowiedź

Najlepsza odpowiedź

W twoim <script> Tag:

function data() {
    'use strict';

    // Get today's date
    var today = new Date();

    // Create an array of month names for the month fields
    var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

    // Increase date by 1 day
    today = new Date(today.valueOf() + 86400000);

    // Set the values
    document.getElementById('day').value = today.getUTCDate();
    document.getElementById('month').value = monthNames[today.getUTCMonth()];
    document.getElementById('year').value = today.getUTCFullYear();
}

// Automatically do this on load
window.addEventListener('load', data, false);

I usuń atrybut onload z tagu body.

Zobacz jsfiddle.

1
rink.attendant.6 13 sierpień 2014, 19:02