Ger*_*cke 10 twitter-bootstrap knockout.js
我想使用bootstrap datepicker并将所选日期与knockoutjs绑定.
使用datepicker的函数:
$(function() {
// create the departure date
$('#depart-date').datepicker({
autoclose: true,
format: 'yyyy/mm/dd',
}).on('changeDate', function(ev) {
ConfigureReturnDate();
});
$('#return-date').datepicker({
autoclose: true,
format: 'yyyy/mm/dd',
startDate: $('#depart-date').val()
});
// Set the min date on page load
ConfigureReturnDate();
// Resets the min date of the return date
function ConfigureReturnDate() {
$('#return-date').datepicker('setStartDate', $('#depart-date').val());
}
});
Run Code Online (Sandbox Code Playgroud)
这是我想要使用的小提琴,但不知道如何去做. http://jsfiddle.net/zNbUT/276/
我找到了一个帮助我的小提琴 http://jsfiddle.net/jearles/HLVfA/6/
来自小提琴的功能:
ko.bindingHandlers.datepicker = {
init: function (element, valueAccessor, allBindingsAccessor) {
//initialize datepicker with some optional options
var options = allBindingsAccessor().datepickerOptions || {};
$(element).datepicker(options).on("changeDate", function (ev) {
var observable = valueAccessor();
observable(ev.date);
});
},
update: function (element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).datepicker("setValue", value);
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10426 次 |
| 最近记录: |