简体   繁体   English

Jquery日期选择器 - 日期格式问题

[英]Jquery date picker - date format issue

I am using the Jquery date picker to select a date. 我正在使用Jquery日期选择器来选择日期。 When I select a date the format of the date in the textbox is mm-dd-yyyy and I would like dd-mm-yyyy. 当我选择日期时,文本框中日期的格式为mm-dd-yyyy,我想要dd-mm-yyyy。

Textbox 文本框

Date: <input type="text" id="datepicker"/>

JQuery JQuery的

$(function() {
$( "#datepicker" ).datepicker({ dateFormat: "dd/mm/yy"});
});

If I then adapt the text box by including a default date: 如果我然后通过包含默认日期来调整文本框:

<input type="text" value="<?php echo date("d/m/Y"); ?>" id="datepicker" />

The default date appears as I would like in the input box ie dd/mm/yy, but when I open the date picker it takes this date as mm/dd/yy and therefore opens the date picker on the wrong date. 默认日期在输入框中显示为我想要的,即dd / mm / yy,但是当我打开日期选择器时,它将此日期视为mm / dd / yy,因此在错误的日期打开日期选择器。

The text box and the picker do not seem to thinking in the same format. 文本框和选择器似乎没有考虑相同的格式。 How do I correct this? 我该如何纠正?

UPDATE UPDATE

The issue is now: 问题是:

1 - when I open the page the default date in textbox is correct and in the right format dd/mm/yy 1 - 当我打开页面时,文本框中的默认日期是正确的,格式正确为dd / mm / yy

2 - when I open the date picker the date picker goes to the correct date ie the default date 2 - 当我打开日期选择器时,日期选择器会转到正确的日期,即默认日期

3 - when I then choose a date from the date picker the format reverts to mm/dd/yy in the text box 3 - 当我从日期选择器中选择日期时,文本框中的格式将恢复为mm / dd / yy

Does, when using JQuery to update an id, the format of the text box get bypassed in some way? 当使用JQuery更新id时,文本框的格式是否会以某种方式被绕过?

You've actually changed the type attribute of your input box to a date . 您实际上已将输入框的type属性更改为date Keep it as text and it should be fine: 保留为文本,应该没问题:

<input type="text" value="<?php echo date("d/m/Y"); ?>" id="datepicker" />

Here's one specific for your code: 这是针对您的代码的特定内容:

var date = $('#datepicker').datepicker("option", "dateFormat", "dd/mm/yy");

More general info available here: 更多一般信息在这里:

http://api.jqueryui.com/datepicker/#option http://api.jqueryui.com/datepicker/#option

http://api.jqueryui.com/datepicker/#utility-formatDate http://api.jqueryui.com/datepicker/#utility-formatDate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM