Change default text “Enter a Location” In Google Maps Places API

℡╲_俬逩灬. 提交于 2019-12-06 16:35:49

问题


I've looked all over the internet trying to find an answer to my problem, and the closest thing I've found to an answer is another Stack Overflow question, here: How do i change the default text in Google Maps API Places Autocomplete

The problem is that either the OP did not have quite the same requirements as myself, or they didn't quite make it clear if they do.

I'm looking for a way to take the default "Enter a Location" in the text input field, and replace it with something else while keeping the same functionality. i.e. have the text disappear on focus, and reappear when it loses focus if no text was entered.

In my current attempt, I've tried to replace the text using a jQuery plugin. It works visually on pageload, but when clicked, "Enter a Location" pops up again, and disappears when text is entered, or the input loses focus (as opposed to the text entry field going blank as intended).

Can anyone give me a pointer here?

Thanks in advance.


回答1:


Just set the placeholder attribute of the input element to which you are attaching the autocomplete to whatever you want:

<input type="text" placeholder="Some new text">

This is detailed in the documentation:

By default, the text field created by the Autocomplete service contains standard placeholder text. To modify the text, set the placeholder attribute on the input element.



来源:https://stackoverflow.com/questions/9379192/change-default-text-enter-a-location-in-google-maps-places-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!