我有一個表單,其中onsubmit執行一些功能。我怎麼能確定func2();僅在func1();成功運行?和func3();只有在2和1的時候?表單,只有在以前成功時纔會運行多個函數
<form onsubmit="func1();func2();func3(); return false">
<input type="text" id="start" name="start">
<input type="submit" value="Go">
</form>
例如的功能之一是這樣的:
<script src="https://maps.googleapis.com/maps/api/js?&sensor=false&region=it&libraries=places"></script>
<script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var myLatlng = new google.maps.LatLng(41.88994,12.51383);
var mapOptions = {
zoom:16,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: myLatlng,
styles: [
{
featureType: "poi.business",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
}
]
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('directions-panel'));
var input = document.getElementById('start');
var options = {
types: ['geocode'],
componentRestrictions: {country: 'it'},
rankBy: google.maps.places.RankBy.DISTANCE
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
autocomplete.bindTo('bounds', map);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Studio medico'
});
}
function calcRoute() {
var start = document.getElementById('start').value;
var end = "Via Tiburtina 500, Roma";
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.TRANSIT
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
其他2:
function boxappear() {
document.getElementById("percorsolink").style.display="none";
document.getElementById("percorsoform").style.display="inline";
}
function reducemap() {
document.getElementById("map-canvas").style.width="620px";
google.maps.event.trigger(map, "resize");
}
工程就像一個魅力! :D謝謝! 如果由於某種原因異步操作沒有完成,是否有可能創建瀏覽器彈出錯誤? – MultiformeIngegno 2013-05-01 22:35:09
也許,但我不知道如何。谷歌文檔可能會提供一個例子。 – bfavaretto 2013-05-01 22:43:28
我會搜索!再次感謝! :) – MultiformeIngegno 2013-05-01 22:44:33