我有一个页面基本上是一个巨大的全屏谷歌地图。我无法使用任何类型的焦点功能。有什么想法吗?代码很长,所以这里是URL,然后是一些摘录:
我们正在处理的页面,我们希望位置搜索输入框在页面加载后成为焦点:http://api.raprec.com/maps/frame/
表单字段(注意我还尝试了html5焦点属性,它没有做任何事情:
<input type="text" name="location" id="location" value="" TABINDEX=1 autofocus />
google地图文档中建议的“将表单移动到地图中”的javascript行:
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(document.getElementById('sidepanel'));
页面页脚中的javascript:
jQuery(document).ready(function () {jQuery('#location').focus(); });
答案 0 :(得分:1)
元素只有在可见时才会聚焦。
你的尝试有效,但来得太早,因为当元素移动到它的控制位置时,它会失去焦点。您需要的是在元素已经放置到地图上时设置焦点。因为没有事件可以找出它发生的时间(我不建议在这里使用DOMNodeInserted),所以在设置焦点之前需要延迟。
等待tilesloaded
- 事件似乎已经足够了:
google.maps.event
.addListenerOnce(map,'tilesloaded',function(){jQuery('#location').focus()});
答案 1 :(得分:0)
html5 autofocus属性怎么样?
http://www.w3schools.com/tags/att_input_autofocus.asp
<input type="text" autofocus>