简体   繁体   English

手机 Safari 不接受 HTML5 仪表输入值

[英]Mobile Safari not accepting HTML5 Meter input value

I'm creating an app that tracks your elevation.我正在创建一个跟踪您的高度的应用程序。 Currently IOS is one of the only devices to support the Altitude parameter so it's vital to get it working in mobile Safari. The altitude will be printed in two location on page, in a text element and also in the Meter element so there is a visual representation of your current altitude.目前 IOS 是仅有的支持 Altitude 参数的设备之一,因此让它在移动设备 Safari 中工作至关重要。高度将打印在页面上的两个位置,文本元素和 Meter 元素中,因此有一个视觉您当前高度的表示。

Generating the altitude hasn't been an issue but what I haven't had any success with getting the altitude to store in the Meter's value.生成高度不是问题,但我没有成功地将高度存储在 Meter 的值中。 Something to note is the Mobile Safari doesn't support the Meter element so I am using a polyfill to get it to work at all.需要注意的是 Mobile Safari 不支持 Meter 元素,所以我使用 polyfill 让它工作。

You can get the general idea of what i'm trying to do here: http://jsfiddle.net/qF9hh/您可以在这里大致了解我要做什么: http://jsfiddle.net/qF9hh/

Notice the geolocation coords are commented out, but they do work if you were to test it on an IOS device.请注意,地理定位坐标已被注释掉,但如果您要在 IOS 设备上对其进行测试,它们确实有效。

So my question is, how do I get the Altitude coordinate to store in the Meter??所以我的问题是,如何获取高度坐标以存储在仪表中?

something like this might work better这样的事情可能会更好

var worked = false;
$("button").click(function () {
    worked = false;
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(success, error);
    } else {
        error('not supported');
    }
}).load();​
function error(msg){
    alert(typeof(msg) = "string" ? msg : "error!");
}
function success(pos){
    if(worked)return; // to prevent firing twice in firefox
    worked = true;
    var meter = $("#high");
    if(pos.altitude === null){
        error("Altitide not supported");
        return;
    }
    meter.val(pos.altitude);
    meter.text(pos.altitude + "/" + meter.attr("max"));
}

Jsfiddle小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM