0
试图在输入邮政编码时获取表单以自动填充城市和州的文本框。使用邮政编码输入的自动填充城市和州
下面的代码是我正在尝试使用的。如果我将<asp:TextBox>
替换为<input type..>
它的工作,但我特别需要使用<asp:TextBox>
为我的领域。有没有人有关于如何让这个工作的提示?
这里是它与输入的工作一的jsfiddle:http://jsfiddle.net/7VtHc/5/
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"> </script>
<script type='text/javascript'>
$(window).load(function() {
$(document).ready(function() {
$("#zipTxtBox").keyup(function() {
var el = $(this);
if (el.val().length === 5) {
$.ajax({
url: "http://zip.elevenbasetwo.com",
cache: false,
dataType: "json",
type: "GET",
data: "zip=" + el.val(),
success: function (result, success) {
$("#cityTxtBox").val(result.city);
$("#stateTxtBox").val(result.state);
}
});
}
});
});
});
</script>
<div class="row">
<div class="col-xs-6">
<asp:Label ID="Label13" runat="server" Text="Zip Code" />
<asp:TextBox ID="zipTxtBox" runat="server" />
</div>
<div class="col-xs-3">
<asp:Label ID="Label15" runat="server" Text="City" />
<asp:TextBox ID="cityTxtBox" runat="server" />
</div>
<div class="col-xs-2">
<asp:Label ID="Label16" runat="server" Text="State" />
<asp:TextBox ID="stateTxtBox" runat="server" />
</div>
</div>
更多
static
控制'with' ...'for' ......你能改写ÿ我们的问题?以及哪些数字对邮政编码有效,以便我们可以对其进行测试? – balexandre@balexandre,修复隐藏的代码。 – gunr2171
@balexandre我使用60440作为邮政编码 – techora