<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>二级省市联动</title>
<script src="../js/jquery-1.11.1.js"></script>
<script>
$(function() {
var shengfen = [["邯郸", "仓州"], ["安阳", "洛阳"]];
//给省份选项改变的事件
$("#pro").change(function() {
//清空上次
$("#cityx").siblings().remove();
var sheng = $(this).val();//省份对应value
for(var i = 0; i < shengfen[sheng].length; i++) {
var $o = $("<option></option>");//创建option标签
$o.html(shengfen[sheng][i]);
$("#city").append($o);
}
});
});
</script>
</head>
<body>
<form>
<select id="pro">
<option>---请选择省份</option>
<option value="0">河北省</option>
<option value="1">河南省</option>
</select>
<select id="city">
<option id="cityx">---请选择城市</option>
</select>
</form>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>二级省市联动</title>
<script src="../js/jquery-1.11.1.js"></script>
<script>
$(function() {
var shengfen = [["邯郸", "仓州"], ["安阳", "洛阳"]];
//给省份选项改变的事件
$("#pro").change(function() {
//清空上次
$("#cityx").siblings().remove();
var sheng = $(this).val();//省份对应value
for(var i = 0; i < shengfen[sheng].length; i++) {
var $o = $("<option></option>");//创建option标签
$o.html(shengfen[sheng][i]);
$("#city").append($o);
}
});
});
</script>
</head>
<body>
<form>
<select id="pro">
<option>---请选择省份</option>
<option value="0">河北省</option>
<option value="1">河南省</option>
</select>
<select id="city">
<option id="cityx">---请选择城市</option>
</select>
</form>
</body>
</html>