问题
I am trying to build a webpage where I have 2 scrollers to pick a range of dates. Both text inputs are the same class, so i am setting the 2 scrollers like so:
$('.datetime').scroller({
preset: 'datetime', minDate: new Date(now.getFullYear(), now.getMonth(), (now.getDate() - 7)), theme: 'default', display: 'modal', timeFormat: 'HH:ii', timeWheels: 'HHii', stepMinute: 5, mode: 'scroller'
});
What I'd like to do is to get the 2nd scroller to set as its minDate the value set by the first scroller.
I tried setting up the scrollers separately, using the eq() function & setting the minDate of the second to $('.datetime').eq(0).val(). I found 2 problems with that: the value that is set by mobiscroll in the text input is not recognized as a date; & the value doesn't appear to change, but that may be due to the first error.
Does mobiscroll have a way of parsing the date that it loads into the text input? I'd rather not add another plugin like date.js just to get this one to work how I need it.
回答1:
You can use the getDate method of mobiscroll:
$('.datetime').eq(0).scroller('getDate');
This returns a date object, not a string.
There is also a parseDate utility function
$.scroller.parseDate(format, strValue);
For more information see http://docs.mobiscroll.com/datetime-preset
来源:https://stackoverflow.com/questions/11852970/using-mobiscroll-for-a-date-range