移动Safari(10.3.1)DateTime-Local“输入有效值"错误 [英] Mobile Safari (10.3.1) DateTime-Local "Enter a Valid Value" Error

查看:149
本文介绍了移动Safari(10.3.1)DateTime-Local“输入有效值"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新版本的iOS Mobile Safari上遇到错误. iOS 10.3版之前未发生此错误.有人可以为此指出正确的方向吗?

I'm getting an error on the newer versions of iOS' Mobile Safari. This error didn't happen prior to version 10.3 of iOS. Can someone point me in the right direction on this?

以下是原始的HTML,随附的是经过检查的视图和移动设备(iPhone 7)的视图.

Here's the raw HTML and attached are the inspected view and the view of the mobile device (iPhone 7).

推荐答案

简单的解决方案!

IOS要求在输入字段上设置类型为"datetime-local"的值.

IOS requires a value to be set on an input field with a type of "datetime-local".

示例:<input type="datetime-local" value="2000-07-01T12:00" />

就这样:)

我个人觉得将默认值设置为用户当前的本地时间很好.这必须在ISOTime中格式化,且没有秒,因此其代码可能类似于:

I personally find it nice to set the default value to the users current local time. This has to be formatted in ISOTime without seconds, so the code for this might be something like:

// get the iso time string formatted for usage in an input['type="datetime-local"']
var tzoffset = (new Date()).getTimezoneOffset() * 60000; //offset in milliseconds
var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0,-1);
var localISOTimeWithoutSeconds = localISOTime.slice(0,16);

// select the "datetime-local" input to set the default value on
var dtlInput = document.querySelector('input[type="datetime-local"]');

// set it and forget it ;)
dtlInput.value = localISOTime.slice(0,16);

这篇关于移动Safari(10.3.1)DateTime-Local“输入有效值"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆