JQuery Date Picker动态altField

时间:2013-02-22 13:02:40

标签: jquery uidatepicker

我有一组动态页面,上面有jQuery datepicker字段。

我希望将漂亮的化妆日期写回用户,但是用于提交数据的输入字段是隐藏的。

我看到This other post一切都很好,直到我尝试实现buttonImage方法,以便隐藏我的字段。

jsfiddle demo here

    Date: <input type="text" class="datepicker">&nbsp;
<input type="text" class="datepickeralt" size="30"/>


    $(function () {
        $(".datepicker").datepicker({
            showOn: "button",
            buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
            buttonImageOnly: true,
        });
    });


    $('.datepicker').each(function() {
        console.log(this);
      $(this).datepicker({
        altField: $(this).closest('div').find('.datepickeralt')
      });
    });

起初我以为&#34;这个&#34;附加到图像而不是字段,但是如果你取出第一个功能,控制台记录是完全相同的。

1 个答案:

答案 0 :(得分:2)

尝试使用:

$(function () {
$(".datepicker_sep, .datepicker").each(function(){
$(this).datepicker({
    showOn: "button",
    buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
    buttonImageOnly: true,
    altField: $(this).parent().find('.datepickeralt')
});
})
});

http://jsfiddle.net/jYk6j/3/

相关问题