[英]html5 autofocus not working with google maps v3 infowindow form
我有一個簡單的Google Maps v3應用程序,該應用程序顯示帶有InfoWindow彈出窗口的標記,每個彈出窗口的格式都很小。 我希望焦點在InfoWindow彈出時立即集中在單個輸入元素上,但是到目前為止還沒有運氣。 以下是我正在使用的代碼示例...
var infowindow1 = new google.maps.InfoWindow;
var content = "<div id='infobox'>"+
"Rodney F. Stanley<hr>803-555-5555<br>"+
"1 mile north of allenville<br>"+
"<form name='report' action='updateNotes.php' method='POST'>"+
"<input type='hidden' name='warningID' value='13874794739749' />"+
"<input type='hidden' name='spotterID' value='SC00023' />"+
"<input type='hidden' name='name' value='Rodney F. Stanley' />"+
"<input type='text' name='report' size='25' maxsize='150' placeholder='event and time of occurence' autofocus />"+
"<input type='submit' value='submit' /><br>"+
"</form>"+
"</div>";
infowindow1.setContent(content);
google.maps.event.addListener(marker1, "click", function() {
if(openwindow){
eval(openwindow).close();
}
openwindow=infowindow1;
infowindow1.open(map,marker1);
});
最終解決方案(只是聽眾)...
google.maps.event.addListener(marker1, "click", function() {
if(openwindow){
eval(openwindow).close();
}
openwindow=infowindow1;
infowindow1.open(map,marker1);
google.maps.event.addListener(infowindow1, 'domready', function() {
$("#report").focus();
});
});
您需要使用信息窗口的domready事件並手動設置焦點。
google.maps.event.addListener(infowindow, 'domready', function () {
// Set focus on your input here. Below in jQuery.
$("#yourInput").focus();
});
這將起作用。 自動對焦在這里不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.