我对HTML缺乏经验,不知道为什么这个功能不起作用

时间:2017-04-30 04:36:21

标签: javascript html function google-maps syntax

所以我目前正在使用谷歌地图html api,我正在尝试添加这段代码,当我这样做时,地图完全停止工作。我对HTML没有经验,但如果您知道语法错误或其他一些导致此操作失败的错误,请告诉我可能出现的问题。

Document
it is a test for xpath
it is a test for xpath
$(function(){
    $.ajax({
            url: "/account/getUserInfo",
            async:false,
            dataType:"json",
            success: function(data) {  }
            }
    })
});

1 个答案:

答案 0 :(得分:0)

您的if语句在其条件下缺少括号。这段代码有用吗?

function calc_gallons() {
        var averagempg = parseInt(document.getElementById("averagempg").value):
        var gallons = 0;
        var total = 0;
        var myroute = result.routes[0];
        for (var i = 0; i < myroute.legs.length; i++) {
          total += myroute.legs[i].distance.value;
        }
        total = (total / 1000)*0.621371;
        document.getElementById('total').innerHTML = total;
        if (averagempg > 0) {
            gallons = total / averagempg
            alert('This trip requires' + gallons + 'gallon(s). Have safe travels!')
        }
        else {
            alert('Your average MPG must be a positive number in order to calculate the gallons required for this trip.')
        }
      }