【发布时间】:2015-12-04 03:53:36
【问题描述】:
我添加了一段代码。我担心我的预订页面包含日期选择器和带有一个提交按钮的 ime 选择器。如果用户选择了一些日期和时间,他/她在提交后提交页面,我需要验证用户选择的日期和时间是否与开店日期和时间相匹配。 提交后我写了一些代码,我调用了该函数,但我不知道它是否正确,请有人帮助我。 下面我给出了两个示例,假设用户选择的示例请解决该示例
用户提交后,我们需要使用这些数据进行验证。我在下面添加了代码 $scope.dealers = [{
S_Email_id: "aditiya@gmail.com",
S_Store: "samsung",
status:"",
Store_Name: "Adtiya Samsung Store",
S_Services: "Regular Service,Software Faults,Hardware Faults",
Store_long_description: "Undertake all kind of samsung mobiles",
Store_short_description: "Undertake all kind of samsung mobiles",
Day: {
"monday": "09:10AM - 06:30PM",
"tuesday": "09:10AM - 12:00PM",
"wednesday": "09:10AM - 06:30PM",
"thursday": "09:10AM - 06:30PM",
"friday": "09:10AM - 06:30PM",
"saturday": "10:15AM - 04:15PM",
"sunday": "10:15AM - 04:15PM"
},
},]
例如。 1.如果我用户选择了日期(2015 年 12 月 2 日星期三 00:00:00 GMT+0530(印度标准时间)),这意味着 2015 年 2 月 12 日/星期三,如果用户选择的时间是上午 11:00,我需要与商店确认日期(如上所述)。选定日期(2015 年 12 月 2 日星期三 00:00:00 GMT+0530(印度标准时间))这意味着 2015 年 2 月 12 日/星期三和上午 11:00 的时间匹配商店的营业时间和关闭时间,所以我需要显示警报商店已开业。
2.如果用户选择了日期(2015 年 12 月 3 日星期四 00:00:00 GMT+0530(印度标准时间)),这意味着 2015 年 3 月 12 日/星期四,如果用户选择了 08:00 pm 我需要检查与购物日(如上所述)。选定日期(2015 年 12 月 3 日星期四 00:00:00 GMT+0530(印度标准时间)),这意味着 2015 年 3 月 12 日/星期四和选定时间 08:00 pm 之间不匹配开店和关店时间,所以我需要显示警报店关门或离开
angular.module('myApp', [])
.controller("myCntrl", function($scope, $filter) {
$scope.isOpen = function(dealerSchedule) {
console.log(dealerSchedule);
var udate='Wed Dec 02 2015 00:00:00 GMT+0530 (India Standard Time)';
var now = new Date(udate);
console.log(now);
var times = dealerSchedule[Object.keys(dealerSchedule)[now.getDay() - 1]].replace(/(\d\d\:\d\d)(AM|PM)/g, '1/1/1900 $1 $2').split(" - ");
//var nowTime = new Date('1/1/1900 ' + now.toLocaleTimeString(navigator.language, {
//hour: '2-digit',
//minute: '2-digit',
//hour12: true
//}));
var ntime ='11:00am';
var nowTime = new Date(ntime);
console.log(nowTime);
var response = (times == "Leave" ? "Leave" : (nowTime >= new Date(times[0]) && nowTime <= new Date(times[1]) ? "Open Now" : "Closed Now"));
if(response =='Closed Now' || response =='Leave' )
{
alert('sorry shop closed');
}else
{
alert('shop opened now');
}
};
$scope.dealers = [{
S_Email_id: "aditiya@gmail.com",
S_Store: "samsung",
status:"",
Store_Name: "Adtiya Samsung Store",
S_Services: "Regular Service,Software Faults,Hardware Faults",
Store_long_description: "Undertake all kind of samsung mobiles",
Store_short_description: "Undertake all kind of samsung mobiles",
Day: {
"monday": "09:10AM - 06:30PM",
"tuesday": "09:10AM - 12:00PM",
"wednesday": "09:10AM - 06:30PM",
"thursday": "09:10AM - 06:30PM",
"friday": "09:10AM - 06:30PM",
"saturday": "10:15AM - 04:15PM",
"sunday": "10:15AM - 04:15PM"
},
}, ]
//var date = new Date();
//$scope.hhmmsstt = $filter('date')(new Date(), 'hh:mm:ss a');
//console.log($scope.hhmmsstt);
})
//]]>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.1/angular.min.js'></script>
<div ng-app="myApp">
<div ng-controller="myCntrl">
<label>Search on Label</label>
<br>
<br>
<br>
<div ng-repeat="dealer in dealers">
{{dealer.Store_Name}}
<br>{{dealer.S_Email_id}}
<br>{{dealer.Day}}
<br>
<input type="button" value="order" ng-click="isOpen(dealer.Day)"/>
<br>
<br>
<br>
</div>
</div>
</div>
【问题讨论】:
标签: javascript jquery angularjs