0
我試圖只允許Google地圖infowindow內的TextBox上的有效字符。 '按鍵'事件不是火。請幫我解決這個問題。TextBox按鍵事件不會在Google地圖infowindow中觸發
google.maps.event.addListener(drawingManager, 'polygoncomplete', function(polygon) {
var polylength=polygon.getPath().getArray().length;
var lastarray=polygon.getPath().getAt(polylength-1);
vertex=polygon.getPath().getArray();
var contentString="<form id='myform'>Name:<input name='cname' id='cname' type='text' size='50'></input><br>Address<input name='addr' id='addr' type='text' size='50'></input><br><input type='button' value='submit' onclick='save();'></input></form>";
infowindow = new google.maps.InfoWindow({
content: contentString,
});
infowindow.setPosition(lastarray);
infowindow.open(map);
});
$('input').bind('keypress', function(event){
alert("pressed");
var regex = new RegExp("^[a-zA-Z0-9 ]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
});