ボタンが関数を呼び出すフォームがありますonclick
:
<form>
<input type="text" id="start" name="start">
<input type="button" onclick="calcRoute();" value="Go">
</form>
function calcRoute() {
var start = document.getElementById('start').value;
var end = "My Address in Rome";
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);
}
});
}
Goボタン ( )をクリックすると、すべてのブラウザで正常に動作します<input type="button">
。<input type="text">
に入力してキーボードを押すとENTER(または、たとえばGoiOSキーボードのボタンを押すと)、そうではありません。つまり、キーボードから押すのinput type="button"
ではなく、 を押すと機能ENTERします。どうすればそのように機能させることができますか?
編集:jQueryやその他のフレームワークではありません。:)