jquery datepicker - 两个日期格式相同时发生冲突

发布于 2024-11-26 16:51:35 字数 792 浏览 0 评论 0原文

我有一个带有两个日期字段的表单。这是一个很大的表格,所以我只展示相关部分。

<input id="dateofassessment" name="dateofassessment"  readonly="readonly" class='datebox' />
<input id="LastIncident" name="LastIncident" readonly="readonly" class="datebox" />

(我应该指出,“dateofassessment”是表单中的第一项,“LastIncident”是最后一项)

我像这样附加日期选择器对象。

    $(".datebox").datepicker({
        dateFormat: 'dd-M-yy',
        changeYear: true,
        showButtonPanel: false
        });

“dateofassessment”输入框工作得很好。日历显示正常,单击日期即可填写“评估日期”字段 - 完美!

然而,“LastIncident”框的效果不太好。单击它会显示日历“确定”。但是,选择日期并不填写表格。事实上,日历在“最后事件”处关闭,并在我选择日期后立即在“评估日期”字段中重新打开。

我无法发布完整的代码,因为内部网站上有大量代码。但希望我已经发布了相关部分。

仅供参考,这些字段是“只读”的事实没有任何区别。

版本... jQuery v1.5.1 日期选择器 1.8.9

I have a form with two date fields. It's quite a big form, so I'll just show the relevant parts.

<input id="dateofassessment" name="dateofassessment"  readonly="readonly" class='datebox' />
<input id="LastIncident" name="LastIncident" readonly="readonly" class="datebox" />

( I should point out that "dateofassessment" is the first item in the form, and "LastIncident" is the last item )

I attach the datepicker object like this..

    $(".datebox").datepicker({
        dateFormat: 'dd-M-yy',
        changeYear: true,
        showButtonPanel: false
        });

The "dateofassessment" input box works perfectly. The calendar is shown OK, and clicking on a date fills in the "dateofassessment"field - Perfect!

However, the "LastIncident" box doesn't work so well. Clicking on it displays the calendar OK. However, selecting a date does not fill in the form. In fact the calendar closes on the "LastIncident", and re-opens on the "dateofassessment" field as soon as I select a date.

I can't post the entire code as there's vast amounts of it, on an intranet site. But hopefully I have posted the relevant parts.

FYI,The fact the fields are "readonly" doesn't make any difference.

Versions...
jQuery v1.5.1
Datepicker 1.8.9

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

記柔刀 2024-12-03 16:51:35

嗯,这显然是日期选择器的错误。使用

$(".datebox").datepicker({
        dateFormat: 'dd-M-yy',
        changeYear: true,
        showButtonPanel: false
        });

“尝试”

$("#dateofassessment").datepicker({
        dateFormat: 'dd-M-yy',
        changeYear: true,
        showButtonPanel: false
        });

$("#LastIncident").datepicker({
        dateFormat: 'dd-M-yy',
        changeYear: true,
        showButtonPanel: false
        });

我知道它会让您重复自己,这很糟糕,但它可以帮助解决问题。或者您可以尝试另一个日期选择器。或者更新这个新版本

Well that's obviousely bug with datepicker. Insted of using

$(".datebox").datepicker({
        dateFormat: 'dd-M-yy',
        changeYear: true,
        showButtonPanel: false
        });

Try

$("#dateofassessment").datepicker({
        dateFormat: 'dd-M-yy',
        changeYear: true,
        showButtonPanel: false
        });

$("#LastIncident").datepicker({
        dateFormat: 'dd-M-yy',
        changeYear: true,
        showButtonPanel: false
        });

I know it makes you repeat yourself which is bad but it could help to sort out the problem. Or you can try another datepicker. Or update this one the newer version

痕至 2024-12-03 16:51:35

您的问题位于其他地方,请参阅此小提琴,它按预期工作:http://jsfiddle.net/AfmpL/

Your problem is located elsewhere, see this fiddle which works as expected : http://jsfiddle.net/AfmpL/

一瞬间的火花 2024-12-03 16:51:35

您还可以使用 .setDefaults 使所有日期选择器的行为相同(我的母版页中有我的日期选择器,甚至不在 OnDocumentReady 中,因为我希望它在 OnDocumentReady 函数之前运行)。

$.datepicker.setDefaults({
    showOn: "button",
    buttonImage: "/Program/Images/calendar.png",
    buttonImageOnly: true,
    buttonText: ""
})

因此,您几乎不必重复太多内容。

$("#dateofassessment").datepicker();
$("#LastIncident").datepicker();

You can also use .setDefaults to make all datepickers behave the same (I have mine in my masterpage, not even in OnDocumentReady, because I want it run before OnDocumentReady functions).

$.datepicker.setDefaults({
    showOn: "button",
    buttonImage: "/Program/Images/calendar.png",
    buttonImageOnly: true,
    buttonText: ""
})

And therefore, you won't have to repeat yourself nearly as much.

$("#dateofassessment").datepicker();
$("#LastIncident").datepicker();
哆兒滾 2024-12-03 16:51:35

尝试使用此 JavaScript:

$(function() {
    $( "#datepicker" ).datepicker();
    $( "#datepicker" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
});

$(function() {
    $( "#datepicker2" ).datepicker();
    $( "#datepicker2" ).datepicker( "option", "dateFormat", "yy-mm-dd" );   
});

然后使用以下表单字段:

<input type="text" id="datepicker" name="fecha_ingreso" />
<input type="text" id="datepicker2" name="fecha_ingreso2" />

Try using this JavaScript:

$(function() {
    $( "#datepicker" ).datepicker();
    $( "#datepicker" ).datepicker( "option", "dateFormat", "yy-mm-dd" );
});

$(function() {
    $( "#datepicker2" ).datepicker();
    $( "#datepicker2" ).datepicker( "option", "dateFormat", "yy-mm-dd" );   
});

Then use the following form fields:

<input type="text" id="datepicker" name="fecha_ingreso" />
<input type="text" id="datepicker2" name="fecha_ingreso2" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文