【发布时间】:2014-05-09 18:06:29
【问题描述】:
当我输入邮政编码时,尝试获取一个表单来自动填充城市和州文本框。
下面的代码是我正在尝试使用的。如果我用<input type..> 替换<asp:TextBox>,它可以工作,但我特别需要在我的字段中使用<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>
【问题讨论】:
-
with...for... 你能改写你的问题吗?什么号码对邮政编码有效,以便我们进行测试? -
@balexandre,修复了隐藏代码。
-
@balexandre 我使用 60440 作为邮政编码
标签: c# javascript asp.net