-
手机端户籍选择了一级地区,二级地区显示了所有城市
-
-
手机端户籍选择了一级地区,二级地区把所有城市都选择出来了,比如一级地区选择了江苏,二级地区应该属于江苏省下面的市,但是现在无论一级地区选择什么,二级地区都把全部区域包括省、市全部列提出来,电脑端的户籍这一块选择正常。
<div class="varpop-label">
<ul>
<li>
<i>省:</i>
<span>
<!--{assign var="volistdist1" value=vo_list("mod={treearea}")}-->
<select name="town_dist1" id="town_dist1">
<option value="0">选择</option>
<!--{foreach $volistdist1 as $val}-->
<option value="<!--{$val.areaid}-->"<!--{if $dist1==$val.areaid}--> selected<!--{/if}-->><!--{$val.areaname}--></option>
<!--{/foreach}-->
</select>
</span>
<div class="clear"></div>
</li>
<li>
<i>市:</i>
<span>
<select name="town_dist2" id="town_dist2">
<option value="0">选择</option>
<!--{if $dist1>0}-->
<!--{assign var="volistdist2" value=vo_list("mod={childarea} catid={<!--{$dist1}-->}")}-->
<!--{foreach $volistdist2 as $val}-->
<option value="<!--{$val.areaid}-->"<!--{if $dist2==$val.areaid}--> selected<!--{/if}-->><!--{$val.areaname}--></option>
<!--{/foreach}-->
<!--{/if}-->
</select>
</span>
<div class="clear"></div>
</li>
</ul>
<div class="clear"></div>
</div>
<!--//varpop-label End-->
<div class="varpop-button">
<div class="btn-comfirm" id="town-btn-comfirm">确定</div>
<div class="btn-cancel" id="town-btn-cancel">取消</div>
<div class="clear"></div>
</div>
<!--//varpop-button End-->
<script type="text/javascript">
$(function(){
//一级地区切换
var town1_value = 0;
var town1_text = '';
$("#town_dist1").bind("change", function(){
town1_value = $("#town_dist1").find("option:selected").val();
town1_text = $("#town_dist1").find("option:selected").text();
if (town1_value == 0) {
//清空2级地区
$("#town_dist2").empty();
}
else {
//获取二级地区
$.ajax({
type: "OST",
url: WAP_APPFILE+"?c=index&a=gethometown",
cache: false,
data: {rootid:town1_value, r:get_rndnum(8)},
dataType: "json",
success: function(data) {
//清空2级地区
$("#town_dist2").empty();
var option_town2 = "<option value='0'>选择</option>";
$.each(data,function(entryIndex,entry){
option_town2 += "<option value='"+entry.areaid+"'>"+entry.areaname+"</option>";
});
$("#town_dist2").append(option_town2);
},
error: function() {
ToastShow("数据获取失败,请检查网络...");
}
});
}
});
//确定回调数据
$("#town-btn-comfirm").click(function(){
//一级地区
var return_town1_value = $("#town_dist1").find("option:selected").val();
var retrun_town1_text = $("#town_dist1").find("option:selected").text();
//二级地区
var return_town2_value = $("#town_dist2").find("option:selected").val();
var retrun_town2_text = $("#town_dist2").find("option:selected").text();
//选择查询、等操作
$("#hometown1").val(return_town1_value);
$("#hometown2").val(return_town2_value);
$("#hometown_text").text(retrun_town1_text+" "+retrun_town2_text);
hometownPopClose(); //关闭
});
//关闭取消
$("#town-btn-cancel").click(function(){
hometownPopClose();
});
});
</script>
这是代码。
-
1981 次浏览
1 条评论
收藏
1个评论
-
-
Lee
官方认证帐号 2020-12-01 10:00
-
你这个是什么版本的?
V4新版是这样的标签:
<div class=\"varpop-label\">
<ul>
<li>
<i>一级地区:</i>
<span>
<!--{assign var=\"volistdist1\" value=vo_list(\"mod={volisthome1}\")}-->
<select name=\"town_dist1\" id=\"town_dist1\">
<option value=\"0\">选择</option>
<!--{foreach $volistdist1 as $val}-->
<option value=\"<!--{$val.areaid}-->\"<!--{if $dist1==$val.areaid}--> selected<!--{/if}-->><!--{$val.areaname}--></option>
<!--{/foreach}-->
</select>
</span>
<div class=\"clear\"></div>
</li>
<li>
<i>二级地区:</i>
<span>
<select name=\"town_dist2\" id=\"town_dist2\">
<option value=\"0\">选择</option>
<!--{if $dist1>0}-->
<!--{assign var=\"volistdist2\" value=vo_list(\"mod={volisthome2} rootid={<!--{$dist1}-->}\")}-->
<!--{foreach $volistdist2 as $val}-->
<option value=\"<!--{$val.areaid}-->\"<!--{if $dist2==$val.areaid}--> selected<!--{/if}-->><!--{$val.areaname}--></option>
<!--{/foreach}-->
<!--{/if}-->
</select>
</span>
<div class=\"clear\"></div>
</li>
</ul>
<div class=\"clear\"></div>
</div>
<!--//varpop-label End-->
<div class=\"varpop-button\">
<div class=\"btn-comfirm\" id=\"town-btn-comfirm\">确定</div>
<div class=\"btn-cancel\" id=\"town-btn-cancel\">取消</div>
<div class=\"clear\"></div>
</div>
<!--//varpop-button End-->
<script type=\"text/javascript\">
$(function(){
//一级地区切换
var town1_value = 0;
var town1_text = \'\';
$(\"#town_dist1\").bind(\"change\", function(){
town1_value = $(\"#town_dist1\").find(\"option:selected\").val();
town1_text = $(\"#town_dist1\").find(\"option:selected\").text();
if (town1_value == 0) {
//清空2级地区
$(\"#town_dist2\").empty();
}
else {
//获取二级地区
$.ajax({
type: \"OST\",
url: WEBAPP_APPFILE+\"?c=var&a=gethometown\",
cache: false,
data: {rootid:town1_value, r:get_rndnum(8)},
dataType: \"json\",
success: function(data) {
//清空2级地区
$(\"#town_dist2\").empty();
var option_town2 = \"<option value=\'0\'>选择</option>\";
$.each(data,function(entryIndex,entry){
option_town2 += \"<option value=\'\"+entry.areaid+\"\'>\"+entry.areaname+\"</option>\";
});
$(\"#town_dist2\").append(option_town2);
},
error: function() {
ToastShow(\"数据获取失败,请检查网络...\");
}
});
}
});
//确定回调数据
$(\"#town-btn-comfirm\").click(function(){
//一级地区
var return_town1_value = $(\"#town_dist1\").find(\"option:selected\").val();
var retrun_town1_text = $(\"#town_dist1\").find(\"option:selected\").text();
//二级地区
var return_town2_value = $(\"#town_dist2\").find(\"option:selected\").val();
var retrun_town2_text = $(\"#town_dist2\").find(\"option:selected\").text();
<!--{if $module == \"profile\"}-->
if (return_town1_value < 1) {
ToastShow(\"请选择一级地区\");
return false;
}
if (return_town2_value < 1) {
ToastShow(\"请选择二级地区\");
return false;
}
//修改资料
$.ajax({
type: \"OST\",
url: WEBAPP_APPFILE+\"?c=profile&a=savehometown\",
cache: false,
data: {dist1:return_town1_value, dist2:return_town2_value, r:get_rndnum(8)},
dataType: \"json\",
success: function(data) {
var json = eval(data);
var response = json.response;
var result = json.result;
if (response == \'1\') {
//赋值
$(\"#<!--{$item}-->1\").val(return_town1_value);
$(\"#<!--{$item}-->2\").val(return_town2_value);
$(\"#<!--{$item}-->_text\").text(retrun_town1_text+\" \"+retrun_town2_text);
ToastShow(\"设置成功\");
hometownPopClose(); //关闭
}
else {
ToastShow(\"设置失败,请检查网络...\");
}
},
error: function() {
ToastShow(\"设置失败,请检查网络...\");
}
});
<!--{else}-->
//选择查询、等操作
$(\"#<!--{$item}-->1\").val(return_town1_value);
$(\"#<!--{$item}-->2\").val(return_town2_value);
$(\"#<!--{$item}-->_text\").text(retrun_town1_text+\" \"+retrun_town2_text);
hometownPopClose(); //关闭
<!--{/if}-->
});
//关闭取消
$(\"#town-btn-cancel\").click(function(){
hometownPopClose();
});
});
</script>
-
-
回复 · 0条回复
-
作者信息
-
关注
-
试
免费试用
-
咨询热线
-
咨询热线
020-82299 259
-
在线咨询