0

IE関連の問題が再び発生しました。アイデアは次のとおりです。各 td で、チェックボックスには data-name 属性で日付が割り当てられています。フォームが送信されると、チェックした日付が連続しているかどうかを確認しようとしています。連続している場合は、非表示のフィールドを開始日と終了日で更新して、次のページで価格、スペシャルなどの計算を増やします。これは、Chrome や firefox などの実際のブラウザーでは正常に機能します。しかし、IE (およびおそらくサファリ) には問題があります。いくつかのアラートを実行すると、日付が NaN であることがわかります。ここにスニペットがあります:

HTML:

<td><input data-name="30/10/2013" type="checkbox"></td>
<td><input data-name="31/10/2013" type="checkbox"></td>
<td><input data-name="1/11/2013" type="checkbox"></td>

<form id="booking0" onsubmit="return bookingValidation(0)" class="bookings" method="post" action="/anotherpage.asp">
<input type="hidden" name="bookStart" value="">
<input type="hidden" name="bookEnd" value="">
<input class="book" type="submit" name="Submit" value="Next">
</form>

jQuery:

function bookingValidation(formIdentifier){
    var start = 0;
    var checkTheDate;
    var currentDate;
    var diff;
    var days;
    var validity = false;
    var checkCounter = 0

$("tr#row"+formIdentifier).find('td').each(function (){
    var date = $(this).find('input');
    if(!date.attr('data-name') == null || !date.attr('data-name') == "") { //if it exists, check to see if it is checked.
        if( date.prop('checked') ){ //If checkbox is checked

            checkCounter++; // if current checkbox is checked, increment.
            if(start == 0){ //if start == 0, then this is the first date. We want to pass the date value into the forms hidden field    

                checkTheDate = new Date(date.attr('data-name')); //this is first check box that is checked. grab the associated date and save it

                                    $('#booking'+formIdentifier).find('input[name=bookStart]').val(jsToVbDate(checkTheDate)); //set both start and end date, incase customer wants to do a 1 day trip
                $('#booking'+formIdentifier).find('input[name=bookEnd]').val(jsToVbDate(checkTheDate));

                start++; //increment so this if statement will never become true
                validity = false; 
            }
            else{ //

                checkTheDate.setDate( checkTheDate.getDate() + 1); //increment check date to hopefully match current date

                currentDate = new Date(date.attr('data-name')); //grab current date 


                diff = new Date(currentDate - checkTheDate); //subtract current date from check date, will return in milliseconds
                days = diff/1000/60/60/24; //convert milliseconds into days
                if(days <= 0){ //if days is less than or equal to 0, this means that the check date and current date are the same, meaning the checkboxes are consecutive
                    $('#booking'+formIdentifier).find('input[name=bookEnd]').val(jsToVbDate(currentDate)); //update end date with current date

                    validity = true;//passes validation, can continue onto booking
                }
                else{
                    alert("Checks must be consecutive");
                    validity = false; //fails validation, can not continue to booking
                    return false; 
                }
            } 
        } //2nd if
    } //1st if
}); //end .each() loop

//checks how many checkboxes were checked. If 1 or less were checked, validation failed.
if (checkCounter <= 1){
    alert("You must select at a minimum of 2 days");
    validity = false;
}
return validity;

}

function jsToVbDate(dateToFormat){
    var bookStartY = dateToFormat.getFullYear();
    var bookStartM = dateToFormat.getMonth()+1;
    var bookStartD = dateToFormat.getDate();
    var dateToFormat = bookStartY + "-" + bookStartM + "-" + bookStartD;
    return dateToFormat;
}

助けてください!毛が抜け始めました!

4

2 に答える 2

2

IE は使用されている日付形式を使用できないようです。$.datepicker.parseDateを使用してカスタム形式の日付を解析できます。

checkTheDate = $.datepicker.parseDate( 'd/mm/yy', date.data('name'));
于 2013-10-24T01:07:03.940 に答える