我在一个网站上工作,我想使用图标来选择旅行模式,我有一个工作功能,但它只适用于选择输入。有没有办法修改它以与按钮一起使用?
提前致谢!
功能:
function calcRoute() {
var selectedMode = document.getElementById("mode").value;
var request = {
origin: thuis,
destination: kabk,
// Note that Javascript allows us to access the constant
// using square brackets and a string value as its
// "property."
travelMode: google.maps.TravelMode[selectedMode]
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
HTML - 选择输入
<select id="mode" onchange="calcRoute();">
<option value="DRIVING">Driving</option>
<option value="WALKING">Walking</option>
</select>
HTML - 按钮输入 (?)
<form id="mode">
<input type="button" onchange="calcRoute();" value="DRIVING">
<input type="button" onchange="calcRoute();" value="WALKING">
</form>