Javascript 如何从输入中获取日期时间值
我正在使用github的angular项目。当我选择日期和时间时,它工作正常。但是,当我将Javascript 如何从输入中获取日期时间值,javascript,angularjs,angular-bootstrap,Javascript,Angularjs,Angular Bootstrap,我正在使用github的angular项目。当我选择日期和时间时,它工作正常。但是,当我将ng model添加到输入字段并检索它时,输入字段显示为空。它不会根据ng模型更新字段 指令 App.directive('jsDatetimepicker', function () { return { link: function (scope, element, attrs) { var options = (typeof scope.$eval(attrs.jsDatet
ng model
添加到输入字段并检索它时,输入字段显示为空。它不会根据ng模型更新字段
指令
App.directive('jsDatetimepicker', function () {
return {
link: function (scope, element, attrs) {
var options = (typeof scope.$eval(attrs.jsDatetimepicker) !== 'undefined') ? scope.$eval(attrs.jsDatetimepicker) : new Object();
jQuery(element).datetimepicker({
format: options.format ? options.format : false,
useCurrent: options.useCurrent ? options.useCurrent : false,
locale: moment.locale('' + (options.locale ? options.locale : '') +''),
showTodayButton: options.showTodayButton ? options.showTodayButton : false,
showClear: options.showClear ? options.showClear : false,
showClose: options.showClose ? options.showClose : false,
sideBySide: options.sideBySide ? options.sideBySide : false,
inline: options.inline ? options.inline : false,
icons: {
time: 'si si-clock',
date: 'si si-calendar',
up: 'si si-arrow-up',
down: 'si si-arrow-down',
previous: 'si si-arrow-left',
next: 'si si-arrow-right',
today: 'si si-size-actual',
clear: 'si si-trash',
close: 'si si-close'
}
});
}
};
});
HTML
<input id="example-datetimepicker5" data-js-datetimepicker="" type="text" name="example-datetimepicker5" placeholder="Choose a date.." ng-model="news.new_date" class="form-control"/>
<label for="example-datetimepicker5">Date</label>
<button ng-click="CreateNews()" type="button" class="btn btn-sm btn-primary"><i class="fa fa-check"></i> Create</button>
输出
new_date returns empty
预期的
new_date returns datetime
你可以很好地使用这个
$("#example-datetimepicker5").on("dp.change", function() {
$scope.selecteddate = $("#example-datetimepicker5").val();
alert("selected date is " + $scope.selecteddate);
});
我正在使用angularJS,jQuery“$”应该忽略。您可以在angularJS中使用jQuery,但需要为其添加库
$("#example-datetimepicker5").on("dp.change", function() {
$scope.selecteddate = $("#example-datetimepicker5").val();
alert("selected date is " + $scope.selecteddate);
});