使用 jQuery 将内容附加到 DOM 时出现问题(仅在 Safari iOS 上)
Issue appending content to DOM with jQuery (only on Safari iOS)
在成功的AJAX请求之后,我使用Jquery将一些HTML附加到DOM中。
它适用于所有桌面浏览器,iPhone模拟器中的Safari和iPhone上的Chrome。
但是,当我在iOS 8的iPhone 5S上在Safari中进行测试时,有时会附加内容,有时根本不附加任何内容。
我希望使用 iPhone 模拟器会在 Safari 中使用开发人员工具揭示问题,但它不会复制该问题。
我已经考虑了 AJAX 请求中 JSON 响应的长度,但它不是很长,问题仍然存在。我也验证了它,看起来很好。
JS的相关部分:
$tpl == 'some html content';
var $node = $($tpl);
$node.data({
'event_id': event.event_id,
'event_story_id': (event[0] !== undefined) ? event[0].event_story_id : 0,
'date': event.datetotime
});
$node.find('time').each(function(i, e) {
var time = moment(event.event_date_utc);
$(e).html(time.fromNow());
});
$($node).hide().appendTo('#timeline > ul').fadeIn(800);
JSON 响应:
{"status":"success","message":"","comment_image":"https:'/'/s3-eu-west-1.amazonaws.com'/mfstb'/profile'/small'/70-507d37914cdaf.jpg","user":{"title":"Asa Carter's Life Stories","image":"https:'/'/s3-eu-west-1.amazonaws.com'/mfstb'/profile'/small'/70-507d37914cdaf.jpg"},"paging":{"total":46,"limit":3,"pages":16,"page":1,"prev_page":1,"next_page":2},"events":{"0":{"event_id":1373,"event_name":"fgdfgdfg","event_description":"","event_date":"25'/07'/14","event_date_utc":"2014-07-25T16:25:48+00:00","event_datetotime":1406305548,"story_count":{"total":1,"photo":1,"video":0,"audio":0},"owner":1,"comment_count":0,"number_of_comment":2,"stories":{"0":{"event_story_id":"2238","event_story_description":"","event_story_type":"photo","event_story_token":"53d285100e571","event_file_type":"jpg","event_file_url":"https:'/'/s3-eu-west-1.amazonaws.com'/mfstb'/story'/photo'/full'/2238-53d285100e571.jpg","event_medium_url":"https:'/'/s3-eu-west-1.amazonaws.com'/mfstb'/story'/photo'/large'/2238-53d285100e571.jpg","event_thumb_url":"https:'/'/s3-eu-west-1.amazonaws.com'/mfstb'/story'/photo'/small'/2238-53d285100e571.jpg","event_comment":"","processed":"1"}}},"1":{"event_id":1368,"event_name":"Test MP4","event_description":"","event_date":"02'/06'/14","event_date_utc":"2014-06-02T10:21:09+00:00","event_datetotime":1401704469,"story_count":{"total":1,"photo":0,"video":1,"audio":0},"owner":1,"comment_count":0,"number_of_comment":0,"stories":{"0":{"event_story_id":"2230","event_story_description":"","event_story_type":"video","event_story_token":"538c420659e07","event_file_type":"m4v","event_file_url":"https:'/'/s3-eu-west-1.amazonaws.com'/mfstb'/story'/video'/2230-538c420659e07.m4v","event_medium_url":"","event_thumb_url":"https:'/'/s3-eu-west-1.amazonaws.com'/mfstb'/story'/photo'/small'/2230-538c420659e07.jpg","event_comment":"","processed":"1"}}},"2":{"event_id":1367,"event_name":"Testing 3gp video sample","event_description":"","event_date":"01'/06'/14","event_date_utc":"2014-06-01T21:54:22+00:00","event_datetotime":1401659662,"story_count":{"total":1,"photo":0,"video":1,"audio":0},"owner":1,"comment_count":0,"number_of_comment":0,"stories":{"0":{"event_story_id":"2229","event_story_description":"","event_story_type":"video","event_story_token":"538b92ffcf560","event_file_type":"m4v","event_file_url":"https:'/'/s3-eu-west-1.amazonaws.com'/mfstb'/story'/video'/2229-538b92ffcf560.m4v","event_medium_url":"","event_thumb_url":"https:'/'/s3-eu-west-1.amazonaws.com'/mfstb'/story'/photo'/small'/2229-538b92ffcf560.jpg","event_comment":"","processed":"1"}}}},"generated":0.1763}
请改用此 JS 代码。
$tpl == 'some html content';
var $node = $($tpl);
event.preventDefault();
$node.data({
'event_id': event.event_id,
'event_story_id': (event[0] !== undefined) ? event[0].event_story_id : 0,
'date': event.datetotime
});
$node.find('time').each(function(i, e) {
var time = moment(event.event_date_utc);
$(e).html(time.fromNow());
});
$($node).hide().appendTo('#timeline > ul').fadeIn(800);
相关文章:
- ReactJS映射:如何仅在url变量不为空时呈现html链接
- 如何使bxslider仅在移动视图中处于活动状态
- 仅在jQuery函数内部循环问题
- 在iPad上播放的视频-JS问题(仅声音)
- 为什么此字符编码问题仅在选定系统上出现
- 仅在侦听器函数中加载脚本/模块会导致问题吗?
- jQuery .unload() 函数问题,仅在单击特定链接时激活
- 如果 Div 放置在 img 标记的顶部,则不会在 Div 上触发鼠标关闭事件 - 问题仅在 IE 中
- 为什么预期值仅在我在调试模式下运行代码时出现,但在不调试时中断,以及如何解决此问题
- JavaScript中调整图像大小的奇怪问题(仅在Firefox中存在问题)
- 仅在Chrome中调整Iframe大小问题
- 使用 jQuery 将内容附加到 DOM 时出现问题(仅在 Safari iOS 上)
- 在设置条件以仅在数组中存在相应对象时才执行函数时遇到问题
- 仅在Internet Explorer中存在文本重叠问题
- javascript IE问题.仅在IE中不工作
- 仅在firefox上存在Javascript交叉浏览问题
- 仅在IE9中存在pop .js问题
- 仅在IE上,表单DOM id返回“”;为空或不是对象“;问题
- 预加载图像:仅在IE中存在问题
- 安全问题 - 允许用户添加自己的 JavaScript(仅在运行时)