如果选中单选按钮“是”,则需要返回日期选择器功能。我该怎么做呢

单选按钮

<br><label for="return_journey">would you like a return journey?</label><br>
<input type="radio" name="return" value="yes">Yes
<br>
<input type="radio" name="return" value="no">No
</form><br><br>


日期选择器

$(function () {
        $('#datetimepicker6').datetimepicker();
        $('#datetimepicker6').datetimepicker();
        $("#datetimepicker6").on("dp.change",function (e) {
            $('#datetimepicker6').data("DateTimePicker").minDate(e.date);
        });
        $("#datetimepicker6").on("dp.change",function (e) {
            $('#datetimepicker6').data("DateTimePicker").maxDate(e.date);
        });
    });

最佳答案

将更改事件附加到您的输入,并找出已选择的输入。您可以这样做:

$('input[name=return]').on('change', function() {
    if($(this).val() == "yes" && $(this).is(":checked")) {
        // CODE GOES HERE
    }
});


http://jsfiddle.net/cfakmxm9/

08-17 17:42