我只是试图用格式化的日期进行文本输入。在Google Chrome上运行正常,但在Mozilla Firefox(26.0)上运行时显示:Invalid date
。
您可以在两个浏览器中看到并运行我的示例,并希望能理解该问题。
JS代码:
$( "#h_reg_date" ).datepicker();
$("#h_reg_date").datepicker("option", "dateFormat", "yy-M-dd");
$("#save_data").on("click", function(){
var reg_date = $("#h_reg_date").val();
console.log(reg_date);
reg_date = moment(reg_date).format("YYYY/MM/DD");
console.log(reg_date);
return;
});
HTML:
<input type="text" id="h_reg_date"class="abs" style="top:135px; left:150px;" size="10" readonly >
<input type="button" id="save_data" class="abs" style="top:370px; left:-200px;" value="Add Data">
有什么解决办法吗?
将的格式更改datepicker
为:
$("#h_reg_date").datepicker("option", "dateFormat", "yy/mm/dd");
JS小提琴: http ://jsfiddle.net/MMm86/1/
要将日期设置为您要求的格式,请使用:
$( "#h_reg_date" ).datepicker();
$("#h_reg_date").datepicker("option", "dateFormat", "yy/M/dd");
$("#save_data").on("click", function(){
var reg_date = $("#h_reg_date").val();
console.log(reg_date);
reg_date = moment(reg_date).format("YYYY/MMM/DD");
console.log(reg_date);
return;
});
JS小提琴: http ://jsfiddle.net/MMm86/2/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句