Javascript 如何在另一个(第二个)php文件中使用onsubmit函数?
第一个php文件:Javascript 如何在另一个(第二个)php文件中使用onsubmit函数?,javascript,php,html,google-maps,Javascript,Php,Html,Google Maps,第一个php文件: <form onsubmit="showAddress(this.address.value); return false;" method="post" > <h2>Enter Address</h2> <input type="number" class=" typeahead large_inputbox" name="address" maxlength="6"/> <in
<form onsubmit="showAddress(this.address.value); return false;" method="post" >
<h2>Enter Address</h2>
<input type="number" class=" typeahead large_inputbox" name="address" maxlength="6"/>
<input type="submit" value="Submit" class="submit" />
</form>
输入地址
第二个php文件:
function showAddress(address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setMapTypeId(google.maps.MapTypeId.HYBRID);
if (map.getZoom() < 16){map.setZoom(16);}else{}
marker.setPosition(results[0].geometry.location);
posset = 1;
computepos(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
函数showAddress(地址){
var geocoder=new google.maps.geocoder();
geocoder.geocode({'address':address},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
map.setCenter(结果[0].geometry.location);
setMapTypeId(google.maps.MapTypeId.HYBRID);
if(map.getZoom()<16){map.setZoom(16);}else{}
marker.setPosition(结果[0].geometry.location);
posset=1;
computepos(结果[0]。几何体。位置);
}否则{
警报(“地理编码因以下原因未成功:“+状态”);
}
});
}
如何在另一个(第二个)php文件中使用onsubmit函数?您可以在第一个php文件中包含第二个php文件
showAddress
实际上是一个javascript函数,因此必须在当前HTML页面或其中一个包含的javascript文件中定义它
您可以在HTML文件中包含包含函数的php文件:
<script src="php_with_function.php" />
或在php中:
<script>
<?php require "php_with_function.php"; ?>
</script>
为什么要在第二个文件中使用onsubmit()
,因为showAddress参数值用于在google地图上选择地址。。所以我使用showAddress函数..请使用