广告
广告
html/css/javascript您现在的位置是:主页 > html/css/javascript >

省市县三级联动插件

2024-01-26 16:53:06html/css/javascript 149人已围观

省市县三级联动并赋值给input,常用于表单提交。

area.js下载

<div class="selectBox">  
	<select id="s_province" name="s_province"></select>
	<select id="s_city" name="s_city"></select>
	<select id="s_county" name="s_county"></select>
	<input type="text" name="chengshi" val="" notnull="请选择加盟城市">
</div>
<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="/js/area.js"></script>
<script type="text/javascript">
	addressInit('s_province', 's_city', 's_county');
</script>
<script>
$('.selectBox select').change(function(){
    if($(this).attr('name')=="s_province"){
        a = $(this).val();
        sVal = a;
        $(this).siblings('input').val(sVal);
        console.log(sVal)
    } else if($(this).attr('name')=="s_city"){
        b = $(this).val();
        if(b=="县"||b=="市辖区"){
            sVal = a;
        } else{
            sVal = a+b;
        }        
        $(this).siblings('input').val(sVal);
        console.log(sVal)
    } else if($(this).attr('name')=="s_county"){
        c = $(this).val();
        if(b=="县"||b=="市辖区"){
            sVal = a+c;
        } else{
            sVal = a+b+c;
        }        
        $(this).siblings('input').val(sVal);
        console.log(sVal)
    } else{
        sVal = $(this).find("option:selected").val();
        $(this).siblings('input').val(sVal);
        console.log(sVal)
    }
})
</script>

 


扫码添加技术微信【解决问题,仅需10元起】

专注中小企业网站建设、网站安全15年。
熟悉各种CMS,精通PHP+MYSQL、HTML5、CSS3、Javascript等。
承接:企业仿站、网站修改、网站改版、BUG修复、问题处理、二次开发、PSD转HTML、网站被黑、网站漏洞修复等。
专业解决各种疑难杂症,您有任何网站问题都可联系我们技术人员微信。
➥ 可淘宝担保交易,安全无风险

广告
广告
技术微信