更改默认文字“输入位置”在Google地图Places API中 [英] Change default text "Enter a Location" In Google Maps Places API

查看:127
本文介绍了更改默认文字“输入位置”在Google地图Places API中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上查找了所有试图找到我的问题的答案,而且我发现最接近的答案是另一个堆栈溢出问题,在这里:如何更改Google地图API地图自动填充功能中的默认文字?



问题是,OP的要求与我自己的要求不一样,或者他们没有完全清楚。 b
$ b

我正在寻找一种方法在文本输入字段中采用默认的输入位置,并在保持相同功能的同时将其替换为其他 。即让文字在焦点上消失,并且如果没有文字输入,则在焦点丢失时重新出现。

在我目前的尝试中,我试图用jQuery插件替换文本。它可以在页面加载时以可视方式工作,但是当点击时,输入位置会再次弹出,并且在输入文本时消失,或者输入失去焦点(而不是文本输入字段按预期空白)。 b
$ b

任何人都可以在这里给我一个指针吗?



预先感谢。只需将元素的属性设置为您的元素元素> 将自动完成附加到任何你想要的:

 < input type =textplaceholder =Some new text> 

详情请参阅文档/ javascript / places-autocomplete#placeholder_textrel =noreferrer>文档
$ b


默认情况下,由自动填充服务
创建的字段包含标准占位符文本。要修改文本,请在输入元素上设置
placeholder属性。



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.

解决方案

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.

这篇关于更改默认文字“输入位置”在Google地图Places API中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆