我正在点击按钮搜索位置。结果是 onclick 按钮。但是我在提交函数中输入了相同的代码,但是这里的搜索不起作用。
在按钮单击代码上。(这是有效的)
$("#gobuttton").click(function() {
$("#gmaplatlon").validate({
rules:{"latitude":{number:true}, "longitude":{number:true}, "zoom":{digits:true,min:0}},
errorPlacement:errorMessages
});
$("#address").change(function(){
geocoder.geocode({"address": $(this).attr("value")}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setZoom(16); map.setCenter(results[0].geometry.location); } else { alert("Geocode was not successful for the following reason: " + status); } });
});
});
按输入按钮代码(相同但不起作用)
$('#frm').keypress(function(e) {
var code = e.keyCode;
if(code === 13){
e.preventDefault();
alert(code);
$("#gmaplatlon").validate({rules:{"latitude":{number:true}, "longitude":{number:true}, "zoom":{digits:true,min:0}}, errorPlacement:errorMessages});
$("#address").change(function(){ geocoder.geocode({"address": $(this).attr("value")}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setZoom(16); map.setCenter(results[0].geometry.location); } else { alert("Geocode was not successful for the following reason: " + status); } }); });
}
});
我的功能是 - 在文本框中输入地址并按回车键,然后它应该在谷歌地图上搜索,这是在按钮点击时执行的,但不是在按下回车键时执行的。
HTML代码如下
<form method="post" name="frm" id="frm" enctype="multipart/form-data" action="<?php echo site_url('home/sendmapdata');?>">
<input name="address" type="text" id="address" border: solid 1px; " size="60" value="Search from address" onClick="this.value=''">
<input type="button" id="gobuttton" value="go">
<div id="map_canvas" style="height: 480px; width:665px; " ></div>
<input type="hidden" name="gmaplatlon" value="true">
<p align="center">
<input type="submit" name="okbutton" value="OK" >
</p>
</form>