我有一个 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" );
}