我在后端使用nodejs,对于日期选择器我正在使用jquery插件。
我的结束日期不应该小于开始日期,所以我使用以下代码
<div class="ipfield">
<label class="plclabel" for="role_type">Start Date</label>
<div class='input-group date' id='datetimepicker1'>
<input type="text" name="startdate" id="datepicker1" ng-model="userdatas.start_date" class="txt_box" id="datepicker1" autocomplete="off">
</div>
</div>
<div class="ipfield">
<label class="plclabel" for="role_type">End Date</label>
<div class='input-group date' id='datetimepicker1'>
<input type="text" id="datepicker2" name="enddate" ng-model="userdatas.end_date" class="txt_box" id="datepicker2" autocomplete="off">
</div>
</div>
$( function() {
$("#datepicker1").datepicker({
changeMonth: true,
minDate: dateToday,
changeYear: true,
dateFormat:'dd-M-yy',
onSelect: function(selected) {
$("#datepicker2").datepicker("option","minDate", selected)
}
});
$("#datepicker2").datepicker({
changeMonth: true,
changeYear: true,
dateFormat:'dd-M-yy',
onSelect: function(selected) {
$("#datepicker1").datepicker("option","maxDate", selected)
}
});
});
在后端获取未定义的数据
app.post('/add_notification', function (req, res, next) {
console.log(req.body.msg['start_date'])
console.log(req.body.msg['end_date'])
});
更新
我通过angularjs发送请求
var app = angular.module('app', ['countrySelect','ui.bootstrap','angularMoment','msl.uploads','angularFileUpload', 'ngMessages','ngTagsInput','ui-notification','angularUtils.directives.dirPagination']);
app.controller('settingsCtrl', function($scope, $http,$filter,Notification)
{
$scope.add_notification = function(msg){
console.log(msg) // here itself am not getting the value
$http.post('/add_notification',{'msg':msg}).then(function(response)
{
$('#editModal').modal('toggle');
if(response.data=='error')
{
Notification.error('<span class="glyphicon glyphicon-ok"></span><strong>Error !Please Try Again</strong>');
}
else
{
Notification.success('<span class="glyphicon glyphicon-ok"></span><strong>Your news/event is saved and will be visible to all users for the time period choosen.</strong>');
}
$scope.load_notification();
});
}
})
如果我没有使用onSelect我获取数据,但我的结束日期不应该小于开始日期。
我的代码中有错误吗?
答案 0 :(得分:1)
onselect
。
onchange
指的是修改输入或选择元素(documentation on w3schools)。
使用在您感兴趣的更改(更新输入)完成后触发的不同事件触发器,您可能会更好运。