为什么当点击这个jquery日期选择器时,单选按钮会重置?

Why are the radio buttons resetting when clicking on this jquery datepicker

本文关键字:单选按钮 选择器 日期 jquery 为什么      更新时间:2023-09-26

这是日期拾取器的jquery:

$.fn.dcalendarpicker = function(opts){
    return $(this).each(function(){
        var that = $(this);
        var cal = $('<table class="calendar"></table>'), hovered = false, selectedDate = false;
        that.wrap($('<div class="datepicker" style="display:inline-block;position:relative;"></div>'));
        cal.css({
            position:'absolute',
            left:0, display:'none',
            'box-shadow':'0 4px 6px 1px rgba(0, 0, 0, 0.14)',
            width:'230px',
        }).appendTo(that.parent());
        if(opts){
            opts.mode = 'datepicker';
            cal.dcalendar(opts);
        }
        else
            cal.dcalendar({mode: 'datepicker'});
        cal.hover(function(){
            hovered = true;
        }, function(){
            hovered = false;
        }).on('click', function(){
            // SCRIPT MOD - skip radio buttons
            if(!selectedDate)
                that.focus();
            else {
                selectedDate = false;
                $(this).hide();
            }
        }).on('selectdate', function(e){
            that.val(e.date).trigger('onchange');
            that.trigger($.Event('dateselected',{date: e.date, elem: that}));
            selectedDate = true;
        });
        that.on('keydown', function(e){ if(e.which) return false; })
            .on('focus', function(){
                $('.datepicker').find('.calendar').not(cal).hide();
                cal.show();
            })
            .on('blur', function(){ if(!hovered) cal.hide(); });
    });
}

这里是php/html:

echo "<fieldset>";
        echo "<h5>Select Your Delivery Date:  </h5>";
        echo "<label class='"error_label'">".$error_juice_delivery."</label>";
        echo "<label>Select weekly or monthly deliveries:  <label><br>";
        $type_1 = $type_2 = '';
        if($delivery_type === '1') $type_1 = 'checked';
        else $type_2 = 'checked';
        echo "Weekly <input type='"radio'" name='"delivery_date_type'" value='"1'" $type_1 /><br>";
        echo "Monthly <input type='"radio'" name='"delivery_date_type'" value='"2'" $type_2 /><br>";
        echo "<br><label>Type in delivery start date(has to be atleast one week from today)</label>";
        echo "(mm/dd/yyyy) <input id ='"calendar-demo'" type='"text'" name='"delivery_start_date'" value='"".$delivery_date."'"/><br>";
    echo "</fieldset>";

出于某种原因,每次我点击上面字段集中的日期输入字段,并从jquery日期拾取器下拉菜单中选择一个日期,每周/每月的单选按钮选择被重置,我不知道为什么…

我明白了…我有一个标签标签unclosed:

echo "<label>Select weekly or monthly deliveries:  <label><br>";
应:

echo "<label>Select weekly or monthly deliveries:  </label><br>";