问题描述
我想通过日期框控件以编程方式设置输入日期,为此,我知道我可以使用类似的东西
I want to programmatically set date for the input with datebox control, For this i know i can use something like this
$(element).trigger('datebox', {'method':'set', 'value':'dateString'});
但这似乎并没有更新控件(即当我打开日历时,它设置为当前日期,并且不等于输入字段中的值)
but this doesn't seem to update the control(i.e when i open the calendar, it is set to current date and not equal to the value in the input field)
根据JTsage的指针,我将sth这样的默认日期格式改写为mm/dd/yyyy.
based on JTsage's pointers i overwrote the default dateformat to mm/dd/yyyy, using sth like this.
jQuery.extend(jQuery.mobile.datebox.prototype.options.lang, {
'en': {
dateFormat: '%m/%d/%Y'
}
});
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
useLang: 'en'
});
然后我尝试使用sth这样设置日期
Then i tried setting the date using sth like this
$(element).trigger('datebox', {'method':'set', value:'07/02/2012'});
但是当我导航到页面时此日期没有出现.有趣的是,当我尝试从Firebug控制台(位于该页面上)更新日期时,它更新了该字段以及datebox控件.
but this date is not appearing when i navigate to the page..Interestingly when i tried updating the date from firebug console(being on that page) it updated the field as well as datebox control.
我不知道为什么会这样.需要帮助,请回复JT
I have no idea why this is happening..Need help, please respond JT
推荐答案
所以最终我通过执行此操作解决了该问题
So finally i fixed the issue, by doing this
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
'overrideDateFormat': '%m-%d-%Y',
'overrideHeaderFormat': '%m-%d-%Y'
});
显式设置输入字段的值
$(element).val('06-21-2012');
然后刷新日期框
$(element).trigger('datebox', {'method':'set', 'value':'06-21-2012'});
这篇关于如何在jQuery Mobile Datebox插件1.1.0中以编程方式设置日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!