我刚创建输入日期字段并尝试更改格式。但无法实现。这有可能改变格式吗?
代码段:
<form>
<input value="i want to show 09/09/2015" /><br><br/><br/>
<input type="date" id="dt" value="2014-09-09"/>
</form>
http://jsfiddle.net/HudMe/626/
我想显示dd / mm / yyyy格式。
答案 0 :(得分:0)
假设您要更改<input type='date'>
格式,因此无法更改<input type="date">
中的格式。
但您可以使用https://jqueryui.com/datepicker/代替它。另见http://api.jqueryui.com/datepicker/。
您可以更改日期格式,如下所示:
$.datepicker.formatDate( "yy-mm-dd", new Date( 2007, 1 - 1, 26 ) );
答案 1 :(得分:0)
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
</html>
您可以通过以下方式更改dat的格式:
$(function() {
$( "#datepicker" ).datepicker();
$( "#format" ).change(function() {
$( "#datepicker" ).datepicker( "option", "dateFormat", <SPECIFY Date Formate here>);
});
});
答案 2 :(得分:0)
在谷歌浏览器中它运行正常!
对于firefox
添加小js
(function(){
var target = document.getElementById("dt");
var val = target.getAttribute ('value');
val = val.split("-").reverse().join('-');
target.setAttribute('value',val);
})();
小提琴
答案 3 :(得分:0)
使用以下日期选择器。 https://jqueryui.com/datepicker/
在下面添加您的脚本。
$('#datepicker').datepicker({
dateFormat: 'dd-mm-yy'
});