获取月份功能不适用于 iPad
Posted
技术标签:
【中文标题】获取月份功能不适用于 iPad【英文标题】:Get months function is not working with iPad 【发布时间】:2015-06-08 09:40:48 【问题描述】:我需要在 iPad 上显示月份和日期,但问题是:
在显示月份时,显示undefined
;
在放映日显示null
或nan
。
javascript 代码
for (var x = 0; x < parsed.length; x++)
var objs = parsed[x];
var id = objs.id;
var eventname = objs.abbr_name;
var date = objs.startDate;
var event_url = objs.event_url;
var city = objs.city;
var country = objs.country;
var time = objs.endDate;
//var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var dateObj = new Date(date);
var months = dateObj.getUTCMonth() + 1;
var month = monthNames[dateObj.getMonth()];
var day = dateObj.getUTCDate();
console.log(month);
console.log(day);
var eventData = [];
if (localStorage.getItem('eventData') === null)
eventData = [];
else
eventData = JSON.parse(localStorage.getItem('eventData'));
var details = ;
details.id = id;
details.eventname = eventname;
details.date = date;
details.event_url = event_url;
details.city = city;
details.country = country;
details.month = month;
details.day = day;
details.time = time;
eventData.push(details);
var jsondata = localStorage.setItem('eventData', JSON.stringify(eventData));
if (x == 0)
var htmlcontent = '<a href="/' + event_url + '"><div class="row_color"><div class="col-xss-12"><p class="small1">Similar Events from your industry in ' + country + '</p> </div><div class="col-xss-1"><div class="circle_image">' + month + ' <br><span class="black_col">' + day + '</span></div></div> <div class="col-xss-8"><p>' + eventname + '</p><div style="padding-left:0px!important;" class="col-xss-8"><div class=""><p class="small22"><span class="orange_col"><i class="fa fa-map-marker icon_rightpadding"></i></span>' + city + ', ' + country + '</p></div></div></div><div class="col-xss-2"><div class="row"><span class=" btn_orange_small pull-right">Attend</span></div></div></div></a>';
else if (x % 2 == 0)
var htmlcontent = '<a href="/' + event_url + '" ><div class="row_color"><div class="col-xss-1"><div class="circle_image">' + month + ' <br><span class="black_col">' + day + '</span></div></div> <div class="col-xss-8"><p>' + eventname + '</p><div style="padding-left:0px!important;" class="col-xss-8"><div class=""><p class="small22"><span class="orange_col"><i class="fa fa-map-marker icon_rightpadding"></i></span>' + city + ', ' + country + '</p></div></div></div><div class="col-xss-2"><div class="row"><span class=" btn_orange_small pull-right">Attend</span></div></div></div></a>';
else
var htmlcontent = '<a href="/' + event_url + '" ><div class="row_color1"><div class="col-xss-1"><div class="circle_image">' + month + ' <br><span class="black_col">' + day + '</span></div></div> <div class="col-xss-8"><p>' + eventname + '</p><div style="padding-left:0px!important;" class="col-xss-8"><div class=""><p class="small22"><span class="orange_col"><i class="fa fa-map-marker icon_rightpadding"></i></span>' + city + ', ' + country + '</p></div></div></div><div class="col-xss-2"><div class="row"><span class=" btn_orange_small pull-right">Attend</span></div></div></div></a>';
$("#notify_bar").append(htmlcontent);
这是我对 json 数据所做的:
我已将所有 json 保存在 localstorage 中。localStorage.eventData:
"["id":210195,"eventname":"Aadi Discount Shopping Fair","date":"2015-07-17","event_url":"aadi-discount-shopping-fair","city":"Chennai","country":"India","month":"Jul","day":17,"time":"2015-07-20","id":210198,"eventname":"Aadi Discount Shopping Fair","date":"2015-07-24","event_url":"aadi-discount-shopping-fair-coimbatore","city":"Coimbatore","country":"India","month":"Jul","day":24,"time":"2015-07-27","id":210215,"eventname":"Aadi Discount Shopping Fair","date":"2015-07-31","event_url":"aadi-discount-shopping-fair-pondicherry","city":"Pondicherry","country":"India","month":"Jul","day":31,"time":"2015-08-03"]"
虽然它可以在所有桌面浏览器中正常工作,但我无法挖掘 iPad 的问题所在。
欢迎提出任何建议。
【问题讨论】:
如果您使用console.log()
,您希望 iPad 上的效果如何?
我已经使用插件来检查日期
哪个插件?你应该在这里附上所有代码,如果你想在这里有人帮助你
还有一个 objs 变量样本
我自己使用了 chrome,它提供了所有设备的兼容性
【参考方案1】:
错误来自var date = objs.startDate;
您的 json 中没有 startDate
这样的键。即使使用 Chrome 桌面,我也会在控制台中获得 undefined
和 NaN
。
将 startDate 替换为 date
即可。
parsed = ["id":210195,"eventname":"Aadi Discount Shopping Fair","date":"2015-07-17","event_url":"aadi-discount-shopping-fair","city":"Chennai","country":"India","month":"Jul","day":17,"time":"2015-07-20","id":210198,"eventname":"Aadi Discount Shopping Fair","date":"2015-07-24","event_url":"aadi-discount-shopping-fair-coimbatore","city":"Coimbatore","country":"India","month":"Jul","day":24,"time":"2015-07-27","id":210215,"eventname":"Aadi Discount Shopping Fair","date":"2015-07-31","event_url":"aadi-discount-shopping-fair-pondicherry","city":"Pondicherry","country":"India","month":"Jul","day":31,"time":"2015-08-03"]
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
for (var x = 0; x < parsed.length; x++)
var objs = parsed[x];
var date = objs.date;
var dateObj = new Date(date);
var month = monthNames[dateObj.getMonth()];
var day = dateObj.getUTCDate();
console.log(month);
console.log(day);
【讨论】:
可以帮助点击目标也无法在 ipad 中工作 我没听懂,抱歉【参考方案2】:据我所知,Safari 不接受带连字符的日期格式。尝试使用斜线:
"date":"2015/07/17"
您好。
【讨论】:
以上是关于获取月份功能不适用于 iPad的主要内容,如果未能解决你的问题,请参考以下文章
单页应用程序模板获取不记名令牌功能不适用于grant_type密码invalid_client错误
在 React 中,我的 POST 获取请求在桌面上有效,但在 iPad 上的 Chrome 上无效,这是怎么回事?
如何在 Safari 浏览器中获取当前位置(城市、州、邮政编码)?
screenShot代码不适用于ipad,适用于iphone