相当新的用户在这里,但我遇到了ziptastic的问题,并且在IE中工作是jquery。适用于所有其他浏览器。这是HTML和jquery:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>Zip Code Lookup Demo</title>
<style>
form label, form input {
display: block;
}
</style>
</head>
<body>
<form id="theform">
<label for="zip">
Zip:
<input type="text" id="zip" />
</label>
<label for="city">
City:
<input type="text" id="city" />
</label>
<label for="state">
State:
<input type="text" id="state" />
</label>
<label for="country">
Country:
<input type="text" id="country" />
</label>
<input type="submit" />
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="jquery.ziptastic.js"></script>
<script type="text/javascript">
(function($) {
$(function() {
var duration = 500;
var elements = {
country: $('#country'),
state: $('#state'),
city: $('#city'),
zip: $('#zip')
}
// Initially hide the city/state/zip
elements.country.parent().hide();
elements.state.parent().hide();
elements.city.parent().hide();
// Initialize the ziptastic and bind to the change of zip code
elements.zip.ziptastic()
.on('zipChange', function(evt, country, state, city, zip) {
elements.country.val(country).parent().show(duration);
elements.state.val(state).parent().show(duration);
elements.city.val(city).parent().show(duration);
});
});
}(jQuery));
</script>
</body>
</html>
关于jquery:
(function( $ ) {
var requests = {};
var zipValid = {
us: /[0-9]{5}(-[0-9]{4})?/
};
$.ziptastic = function(zip, callback){
// Only make unique requests
if(!requests[zip]) {
requests[zip] = $.getJSON('http://zip.elevenbasetwo.com/v2/US/' + zip);
}
// Bind to the finished request
requests[zip].done(function(data) {
callback(data.country, data.state, data.city, zip);
});
// Allow for binding to the deferred object
return requests[zip];
};
$.fn.ziptastic = function( options ) {
return this.each(function() {
var ele = $(this);
ele.on('keyup', function() {
var zip = ele.val();
// TODO Non-US zip codes?
if(zipValid.us.test(zip)) {
$.ziptastic(zip, function(country, state, city) {
// Trigger the updated information
ele.trigger('zipChange', [country, state, city, zip]);
})
}
});
});
};
})( jQuery );
为什么IE无法处理这个问题?适用于Safari,Chrome,Firefox?非常感谢任何帮助..