获取zipcode值而不提交表单PHP变量?
<form>
<input type="text" required name="first_name" placeholder="Enter your first name" /><br><br>
<span class="icon-contact-name"></span>
<input type="text" required name="last_name" placeholder="Enter your last name" /><br><br>
<input type="text" id="zipcode" name="zipcode" required placeholder="ZipCode"><br><br>
<input type="submit">
</form>
答案 0 :(得分:0)
你必须使用javascript。 我是用JQuery做的,你只需添加一个带有id&#39; lat-long&#39;
的div或span<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type='text/javascript'>
$('#zipcode').keyup(function() {
$.get( "https://maps.googleapis.com/maps/api/geocode/json?address=" + $('#zipcode').val() + '&sensor=false', function(data) {
var lat = data.results[0].geometry.location.lat;
var lng = data.results[0].geometry.location.lng;
$('#lat-long').html('Latitude: ' + lat + '<br />Longitude: ' + lng + '<br />')
});
})
</script>