我想知道是否有人可以帮忙。下面的代码允许我使用google api来检索使用UK potscodes的地址详细信息。
在Firefox中一切正常但在Internet Explorer中绝对没有任何效果。我们将非常感激地收到任何指示。
由于
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type='text/javascript'>
$(function(){
(function($) {
$.fn.searchPc = function(options) {
var settings = $.extend({
address1: 'address1',
address2: 'address2',
address3: 'address3',
address4: 'address4'
}, options);
return this.each(function() {
var $el = $(this);
var $form = $el.closest('form');
$form.on('click', '.HiddenBtn', function() {
$.post('http://maps.googleapis.com/maps/api/geocode/json?address='+$el.val()+'&sensor=false', function(r) {
var lat = r['results'][0]['geometry']['location']['lat'];
var lng = r['results'][0]['geometry']['location']['lng'];
$.post('http://maps.googleapis.com/maps/api/geocode/json?latlng='+lat+','+lng+'&sensor=false', function(address) {
$('input[name='+settings.address2+']').val(address['results'][0]['address_components'][1]['long_name']);
$('input[name='+settings.address3+']').val(address['results'][0]['address_components'][2]['long_name']);
$('input[name='+settings.address4+']').val(address['results'][0]['address_components'][3]['long_name']);
});
});
});
});
};
})
(jQuery);
$('input[name=postcode]').searchPc({
address2: 'custom_field'
});
});
</script>
<form id="form" name="form">
<input name="postcode" id="postcode" />
<input name="HiddenBtn" type="button" class="HiddenBtn" value="Find address" id="HiddenBtn" /><br /><br />
<input name="address1" id="address1"/><br />
<input name="custom_field" id="custom_field" /><br />
<input name="address3" id="address3" /><br />
<input name="address4" id="address4" /><br />
</form>