我需要幫助解決我的問題的人,我想在總估計和每分鐘0.35分鐘後添加10%如何添加此腳本我試過var結果:pct/10;沒有做到這一點,有人能以上帝的名義幫助我解決這個問題,我真的很感激這一點。我如何添加%和每分鐘的功能與JavaScript
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<script>
//--------------Settings-------------------------------- \t
//ISO 3166-1 Alpha-2 country code, use http://en.wikipedia.org/wiki/ISO 3166-2_alpha-2#US
var countrycode="US"
//Rate per mil (2.00)
var ratepermi=2.50;
//Minimum fare (60)
var minimum_fare=50;
//Currrency Symbol
var currencysymbol="$";
//Avoid motorways/highways? true/false
var avoidHighways=false;
//Avoid toll roads? true/false
var avoidTolls=false;
//Show summary? true/false
var showsummary=false;
//Disclaimer text
var disclaimer="Please be aware this is only an estimated fare and the final price will be quoted on request"
//----------End Settings-------------------------------- \t
\t
function initialize()
{
\t var options = {componentRestrictions: {country: countrycode}};
\t var input = /** @type {HTMLInputElement} */(document.getElementById('inputfrom'));
\t var searchBoxfrom = new google.maps.places.Autocomplete(input,options);
\t var input = /** @type {HTMLInputElement} */(document.getElementById('inputto'));
\t var searchBoxto = new google.maps.places.Autocomplete(input,options);
}
function ftn_estimate()
{
\t if (document.getElementById('inputfrom').value!="" && document.getElementById('inputto').value!="")
\t {
\t \t var origin = document.getElementById('inputfrom').value;
\t \t var destination = document.getElementById('inputto').value;
\t \t
\t \t var service = new google.maps.DistanceMatrixService();
\t \t service.getDistanceMatrix(
\t \t {
\t \t \t origins: [origin],
\t \t \t destinations: [destination],
\t \t \t travelMode: google.maps.TravelMode.DRIVING,
\t \t \t unitSystem: google.maps.UnitSystem.IMPERIAL,
\t \t \t avoidHighways: avoidHighways,
\t \t \t avoidTolls: avoidTolls,
\t \t }, callback); \t
\t }
}
function callback(response, status) {
if (status != google.maps.DistanceMatrixStatus.OK) {
alert('Error was: ' + status);
} else {
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
for (var i = 0; i < origins.length; i++) {
var results = response.rows[i].elements;
\t
for (var j = 0; j < results.length; j++) {
\t \t if(showsummary)
\t \t {
\t \t \t document.getElementById('summary').innerHTML=origins[i] + ' to ' + destinations[j] + ': ' + results[j].distance.text + ' in '+ results[j].duration.text;
\t \t \t document.getElementById('summary').innerHTML+="<br /><font color='red'>" + disclaimer + "</font>"
\t \t }
\t \t document.getElementById('distance').value=(results[j].distance.value/1609.34).toFixed(1);
\t \t document.getElementById('time').value=(results[j].duration.value/60).toFixed(1);
\t \t
\t \t var calc_fare=(results[j].distance.value/1609.34)*ratepermi;
\t \t
\t \t if (calc_fare<minimum_fare)
\t \t {
\t \t \t calc_fare=minimum_fare;
\t \t } \t
\t \t document.getElementById('fare').value=currencysymbol+calc_fare.toFixed(2);
}
}
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<link href="../../../../css/style.css" rel="stylesheet" type="text/css">
<center>
<div id="formbox">
<h1 class="fare_title">FARE ESTIMATE</h1>
<div class="div1">
<span class="ride">Ride in Style</span><img class="check_icon" src="../../../../check2.png" alt="check1"><span class="ride">Safe and Reliable</span><img class="check_icon" src="../../../../check2.png" alt="check1"><span class="ride">Fully Licensed</span><img class="check_icon" src="../../../../check2.png" alt="check1"/>
</div>
<input id="inputfrom" type="text" placeholder="From" style="width:400px" class="inputform">
<h3 style="margin-top: 10px; color: #3F3F3F; text-transform: uppercase;">to</h3>
<input id="inputto" type="text" placeholder="To" style="width:400px" class="inputto">
<br/>
<input type="button" onclick="ftn_estimate();" value="Estimate Fare" class="fare_button">
<br/><br/>
<table class="resultsbox">
<tr><td class="time_style">Time (mins)</td><td><input id="time" readonly type="text" placeholder="--"></td></tr>
<tr><td class="distance_style">Distance (mi)</td><td><input id="distance" readonly type="text" placeholder="--"></td></tr>
<tr><td class="fare_style">Estimated Fare</td><td><input id="fare" readonly type="text" placeholder="--"></td></tr>
</table>
<span id="summary"></span>
</div>
</center>
如果你只共享代碼的相關部分,並改寫你的問題更清楚這將是一件好事。如果我理解正確,你想爲該值添加10%的值......'variable + = 0.1 * variable' – Guillaume
對不起,如果我沒有澄清我的問題。上面我添加的地方。 var ratepermi = 2.50; var minimum_fare = 50 ;.我想在總費用2.50英鎊+ 0.35 =總額後加10%的費用,然後我想再加上10%來給出估算的最終結果。希望我沒有迷惑你。 – Eden