<style type="text/css">
.labelhide {
-webkit-box-shadow: 0px 1px 0px 0px #f3f3f3 !important;
, inset 0px 1px 2px 0px #f3f3f3 !important;
box-shadow: 0px 1px 0px 0px #f3f3f3 !important;
, inset 0px 1px 2px 0px #f3f3f3 !important;
background: #f8f8f8 !important;
border: 1px solid #f8f8f8 !important;
color: #f3f3f3 !important;
width: 1px !important;
float:left;
}
.leftcss {
float: left;
}
</style>
<script type="text/javascript" src="http://www.shicishu.com/down/provincecity.data.min.js"></script>
<script type="text/javascript" src="http://www.shicishu.com/down/provincecity.min.js"></script>
<tr>
<td>
<asp:Label ID="Label15" runat="server" Text="地区:"></asp:Label>
</td>
<td colspan="3">
<asp:Label runat="server" ID="lbl332city" CssClass="leftcss" ></asp:Label>
<asp:Label runat="server" ID="Label8" CssClass="leftcss" Text="。 请选择市:" ></asp:Label>
<asp:TextBox runat="server" ID="tbcity" CssClass="labelhide"></asp:TextBox>
<div class="form-inline leftcss">
<div data-toggle="provincecity">
<div class="form-group">
<label class="sr-only" for="province1">Province</label>
<select id="province1"></select>
</div>
<div class="form-group">
<label class="sr-only" for="city1">City</label>
<select id="city1" onclick="selectcity()"></select>
</div>
</div>
</div>
</td>
</tr>
<script type="text/javascript">
var vc = document.getElementById(‘<%=lbl332city.ClientID%>‘);
var al = document.getElementById("city1").value;
var vas = document.getElementById(‘<%=tbcity.ClientID%>‘);
if (vc.innerText != "") {
vas.setAttribute("value", vc.innerText);
} else if(vc.innerText == "") {
if (al == "") {
va.setAttribute("value", "");
}
}
function selectcity() {
var a = document.getElementById("city1").value;
var va = document.getElementById(‘<%=tbcity.ClientID%>‘);
vc.innerHTML = a;
if (a != "") {
va.setAttribute("value", a);
} else if (a == "") {
va.setAttribute("value", "");
}
}
</script>
if (Convert.ToInt32(lblID.Text) > 0)
lbl332city.Text= Convert.ToString(data.Rows[0][1]);
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
lbl332city.Text = tbcity.Text;
if (CheckInput())
{
//addinfo/update
//use:
tbcity.Text
}
}
private bool CheckInput()
{
bool Result = true;
if (tbcity.Text=="") {
lblMessage.Text = "请选择城市";
Result = false;
}
return Result;
}
原文:https://www.cnblogs.com/liuguiqing/p/15233411.html