javascript JQuery Mobile UI DatePicker 更改日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6106970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery Mobile UI DatePicker Change Date Format
提问by Satch3000
I am trying to change the date format in the JQM UI Datepicker.
我正在尝试更改 JQM UI Datepicker 中的日期格式。
It's got an input which display's the dates as you change them.
它有一个输入,在您更改日期时显示日期。
I need it to display in dd/mm/yyyy format.
我需要它以 dd/mm/yyyy 格式显示。
Can anyone help please?
有人可以帮忙吗?
UPDATE:
更新:
I'm trying this, but nothing's changing:
我正在尝试这个,但没有任何改变:
<script>
//reset type=date inputs to text
$( document ).bind( "mobileinit", function(){
$.mobile.page.prototype.options.degradeInputs.date = true;
});
</script>
<script language="javascript">
$(document).ready(function() {
$.datepicker.formatDate('dd/mm/yyyy'); //ADDED HERE
$("input[type='submit']").click(function(e) {
e.preventDefault();
});
});
</script>
回答by Abdul Kader
回答by user320478
Change the "jquery.ui.datepicker.mobile.js" file
更改“jquery.ui.datepicker.mobile.js”文件
add date format: dateFormat: "dd/mm/yy" Code shown below
添加日期格式: dateFormat: "dd/mm/yy" 代码如下所示
//bind to pagecreate to automatically enhance date inputs
$( ".ui-page" ).live( "pagecreate", function(){
$( "input[type='date'], input[data-type='date']" ).each(function(){
$(this).after($("<div />").datepicker({ altField: "#" + $(this).attr("id"), showOtherMonths: true, dateFormat: "dd/mm/yy" }));
});
});