亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

LAT 和 LNG 未顯示在 HTML 的輸入表單上

LAT 和 LNG 未顯示在 HTML 的輸入表單上

隔江千里 2023-10-14 15:51:55
我使用下面的代碼獲取我當前位置的 LAT 和 LNG,以將其顯示在輸入表單中,但由于某種原因,它沒有按需要顯示我的 LAT 和 LNG,而是會瞬間顯示 LAT 和 LNG 然后消失。我嘗試更改瀏覽器權限以允許位置,但仍然顯示一閃然后消失。有人可以幫忙嗎?下面是我的代碼:<form>  <button onclick="onFormSubmit()">GET CURRENT LOCATION</button><script type="text/javascript">function onGeoSuccess (position) {        var lat = position.coords.latitude;        var lng = position.coords.longitude;        // NEXT 2 LINES WILL SET VALUE OF RESPECTIVE INPUTS        document.getElementById('lat').value = lat;        document.getElementById('lng').value = lng;        // MAKE API CALL HERE, OR ANY OTHER NEXT STEPS    }    function onGeoError (err) {        console.error("Error while trying to get position", err);    }    function onFormSubmit () {        if (navigator.geolocation) {            navigator.geolocation.getCurrentPosition(onGeoSuccess, onGeoError);        } else {            alert('GeoLocation not supported or not allowed');        }    }</script>              <div class="form-group">                <input type="text" name="lat" class="form-control" id="lat" placeholder="Your Latitude" data-msg="Please enter your latitude">                <div class="validate"></div>              </div><div class="form-group">                <input type="text" name="lng" class="form-control" id="lng" placeholder="Your Longitude" data-msg="Please enter your Longitude">                <div class="validate"></div>              </div>              <div class="form-group">                <input type="text" name="subject" class="form-control" id="contact-subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject">                <div class="validate"></div>              </div></form>我只想在輸入表單上顯示 LAT 和 LNG 以及每個 ID,但我不知道做錯了什么。它沒有按預期顯示。
查看完整描述

1 回答

?
吃雞游戲

TA貢獻1829條經驗 獲得超7個贊

因此,我追溯我的代碼并解決錯誤,發現這只是因為我使用而<button onclick="onFormSubmit()">GET CURRENT LOCATION</button>不是<button onclick=" return onFormSubmit()">GET CURRENT LOCATION</button>. 當我出于某種原因撥打電話時,onFormSubmitonclick會出現一瞬間然后消失,但當我撥打電話時,return onFormSubmit()一切onclick都會正常工作。



查看完整回答
反對 回復 2023-10-14
  • 1 回答
  • 0 關注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號