jquery选择选项不要改变

时间:2013-05-23 12:19:58

标签: jquery

我有一个jquery js文件。下面;

$(document).ready(function () {

var guest = $('#DetailMaxGuest');
var datebegin = $('#DetailDatepicker');
var dateend = $('#DetailDatepickerEnd');
var selectedGuest = $('#DetailMaxGuest option:selected');
var dateToday = new Date();
var kisi;
var btnReservationSend = $('#btn_reservation');
datebegin.datepicker({
    dateFormat: 'dd MM yy',
    defaultDate: "+1w",
    changeMonth: true,
    minDate: dateToday,
    onSelect: function (selectedDate) {
        $("#DetailDatepickerEnd").datepicker("option", "minDate", selectedDate);
    }
});
guest.on('change', function (event) {
    event.preventDefault();
    var result = $('#DetailMaxGuest option:selected').val();
    $('#DetailMaxGuest option:selected').val(result).attr('selected', 'selected');
    var optionselected = $('#DetailMaxGuest option:selected', this);
    var resultparse = parseInt(result);
    var appid = $('#resultid').val();
    var beginDate = datebegin.val();
    var endDate = dateend.val();
    $("#LoadingImage").show();
    if (beginDate.length != 0) {
        datebegin.next('span').empty();
    } else {
        $("#LoadingImage").hide();
        datebegin.next('span').text('Please Select A Begin Day');
    }
    if (endDate.length != 0) {
        dateend.next('span').empty();
    } else {
        $("#LoadingImage").hide();
        dateend.next('span').text('Please Select An End Day');
    }
    if (result != "Select One") {
        selectedGuest.next('span').empty();
    } else {
        $("#LoadingImage").hide();
        selectedGuest.next('span').text('Please Select Guest Number');
    }
    if (beginDate.length != 0 && endDate.length != 0 && result != "Select One") {
        var message = { 'dateEnd': endDate, 'kisi': resultparse, 'resultid': appid, 'dateBegin': beginDate };
        $.ajax({
            url: '/Product/GetResevationResult',
            type: 'GET',
            data: message,
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (data) {
                if (data.error) {
                    $("#LoadingImage").hide();
                    $('#reservation-result').hide();
                    $('#reservation-check').show();
                    $('#reservation-check').html(data.msg).fadeIn(2000);
                    $('#btn_reservation').hide();
                    $('#btn_liste').show();
                } if (data.success) {
                    $("#LoadingImage").hide();
                    $('#reservation-result').show();
                    $('#lblTotalPrice').html(data.toplam).fadeIn(2000);
                    $('#lblDeposit').html(data.deposit).fadeIn(2000);
                    $('#lblTotal').html(data.totalsum).fadeIn(2000);
                    $('#btn_reservation').show();
                    $('#btn_liste').hide();
                }
            }
        });

    }

});
dateend.datepicker({
    dateFormat: 'dd MM yy',
    defaultDate: "+1w",
    changeMonth: true,
    onSelect: function () {

        if (datebegin.val().length != 0) {
            datebegin.next('span').empty();
            dateend.next('span').empty();
            var dt = dateend.val();
            var resultid = $('#resultid').val();
            var datebeginval = datebegin.val();
            var result = selectedGuest.val(); //this value every time Select One...????
            $("#LoadingImage1").show();
            if (result != "Select One") {
                kisi = parseInt(result);
            } else {
                kisi = null;
            }
            var message = {
                'dateEnd': dt, 'kisi': kisi, 'resultid': resultid, 'dateBegin': datebeginval
            };
            $.ajax({
                url: '/Product/GetResevationResult',
                type: 'GET',
                data: message,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (data) {
                    if (data.error) {
                        $("#LoadingImage1").hide();
                        $('#reservation-result').hide();
                        guest.prop('disable', 'disable');
                        $('#reservation-check').show();
                        $('#reservation-check').html(data.msg).fadeIn(2000);
                        $('#btn_reservation').hide();
                        $('#btn_liste').show();
                    } if (data.success) {
                        $("#LoadingImage1").hide();
                        $('#reservation-check').hide();
                        guest.prop('disable', false);
                        if (kisi != null) {
                            $('#reservation-result').show();
                            $('#lblTotalPrice').html(data.toplam).fadeIn(2000);
                            $('#lblDeposit').html(data.deposit).fadeIn(2000);
                            $('#lblTotal').html(data.totalsum).fadeIn(2000);
                            $('#btn_reservation').show();
                            $('#btn_liste').hide();
                        } else {
                            $('#btn_reservation').show();
                            $('#btn_liste').hide();
                        }
                    }
                }
            });
        } else {
            datebegin.next('span').text('Please Select A Begin Day');
        }
    }

});
btnReservationSend.on({
    click: function (event) {
        event.preventDefault();
        var firstDate = $('#DetailDatepicker').val();
        var lastDate = $('#DetailDatepickerEnd').val();
        var maxguest = $('#DetailMaxGuest');
        if (firstDate.length == 0) {
            datebegin.next('span').text('Please Check A Begin Date');

        } else {
            datebegin.next('span').empty();
        }
        if (lastDate.length == 0) {
            dateend.next('span').text('Please Check A Last Date');
        } else {
            dateend.next('span').empty();
        }
        if (selectedGuest.val() == "Select One") {
            maxguest.next('span').text('Please Check Guest Number');
        } else {
            maxguest.next('span').empty();
        }

    }
});


});

$('#DetailMaxGuest')改变没问题时。但是,再次选择$('#DetailDatepickerEnd') value==Select One中的更改。但$('#DetailMaxGuest')选项已更改。我无法在$('#DetailDatepickerEnd')中看到这个价值......出了什么问题?谢谢你的回复。

0 个答案:

没有答案