我确信我只是昏昏欲睡,但我不知道如何使用 Mobiscroll 日期选择器插件的 formatDate 实用函数。
The doc只是说:
formatDate function(format, date, settings) Format a date into a string value with a specified format
当我的输入字段的值发生更改时,我想格式化该值并将其存储在另一个字段中,因此我尝试了以下操作:
<input type="text" id="startTimeInput" onChange="alert(jQuery('#startTimeInput').formatDate('yyyy-MM-dd HH:mm:ss', this.value, ''));"/>
但是,警报从未触发,并且出于某种原因 Firebug 现在正在为我播放,因此也没有报告任何内容。有人有什么想法吗?
注意:我使用 jQuery(),因为我必须使用 jQuery.noConflict()
最佳答案
您应该将其用作:
jQuery.scroller.formatDate('yyyy-MM-dd HH:mm:ss', new Date(this.value));
编辑:
formatDate 的第二个参数必须是日期对象,而不是字符串。
我的示例中的 new Date(this.value) 形式可能适用于某些日期格式,但并非总是如此。
如果您想先将其转换为日期(并且您知道格式),请使用:
jQuery.scroller.formatDate('yyyy-MM-dd HH:mm:ss', jQuery.scroller.parseDate(yourInputFormat, this.value));
关于jquery - 使用 Mobiscroll jQuery 插件的 formatDate 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7493944/