-1

我们在我的工作场所使用 jquery UI 1.8.23。我之前问过这个问题,但我没有进一步前进: jQuery UI datepicker - Trying to capture click event from date clicked

如何捕获 onSelect 中的日期并将值传递给已附加 jQuery 到搜索表单的字段。

$('#search-form').append('<input id="dateHidden" name="dateHidden" type="text" />');

$('#datepicker2').click(function(){
    $('#ui-datepicker-div').append('<form><input id="selectMonth" type="button" value="Whole month"></form>');
});

$('#datepicker2').datepicker({
    // The hidden field to receive the date
    altField: "#dateHidden",
    // The format you want
    altFormat: "yy-mm-dd",
    // The format the user actually sees
    dateFormat: "dd/mm/yy",
    onSelect: function (date) {
        $('a.ui-state-default').removeClass('ui-state-highlight');
        $(this).addClass('ui-state-highlight');
    }
});

http://jsfiddle.net/bitmapshades/LFpwN/7/

感谢您查看我的代码,感谢你们提供的任何帮助。

4

1 回答 1

0

问题在于页面和 Javascript 端的 HTML 标记:

HTML

<!-- The tag wasn't closed and you can't have the class 'hasDatePicker' set beforehand -->
<input type="text" name="datePicker" id="datepicker2" />

Javascript

// The input tag wasn't closed here either
$('#search-form').append('<input id="dateHidden" name="date" type="hidden" />');

演示:http: //jsfiddle.net/LFpwN/9/

于 2013-09-06T10:59:36.737 回答