根据所选的HTML下拉选项显示谷歌地图位置

时间:2018-02-20 21:03:03

标签: html google-maps

从html下拉表单中选择一个选项后,是否可以立即在Google地图上显示位置?

<select class="js-select2" name="service">
    <option>test1</option>
    <option>test2</option>
    <option>test3</option>
    <option>test4</option>
</select>

例如,我将位置A分配给“test1”,将位置B分配给“test2”。如何选择“test1”谷歌地图将立即在地图上显示位置A,如果我点击“test2”,相同的地图会立即显示位置B?

提前谢谢。

1 个答案:

答案 0 :(得分:2)

是的,有可能。您只需在onchange="myFunction()" html标记中加入select即可。这样,你的原始标签

<select class="js-select2" name="service">

将更改为

<select class="js-select2" name="service" onchange="myFunction()>

稍后您在myFunction()中实施javascript代码,以使用所选位置调整您的地图。

更多信息:https://www.w3.org/TR/WCAG20-TECHS/SCR19.html