<script type="text/javascript" src="cityjs"></script>
<select name="province" onChange="set_city(this, thisformcity);">
<option value="0">选择省</option>
<option value="北京市">北京市</option>
<option value="上海市">上海市</option>
<option value="天津市">天津市</option>
<option value="重庆市">重庆市</option>
<option value="河北省">河北省</option>
<option value="山西省">山西省</option>
</select>
<select name="city" id="citys" >
<option value="0">选择城市</option>
</select>
cityjs文件:
cities = new Object();
cities['北京市']=new Array('北京市区', '北京市辖区');
cities['上海市']=new Array('上海市区', '上海市辖区');
cities['天津市']=new Array('天津市区', '天津市辖区');
cities['重庆市']=new Array('重庆市区', '重庆市辖区');
cities['中国台湾']=new Array('中国台湾');
cities['中国香港']=new Array('中国香港');
cities['中国澳门']=new Array('中国澳门');
cities['河北省']=new Array('石家庄', '张家口市', '承德市', '秦皇岛市', '唐山市', '廊坊市', '保定市', '沧州市', '衡水市', '邢台市', '邯郸市');
cities['山西省']=new Array('太原市', '大同市', '朔州市', '阳泉市', '长治市', '晋城市', '忻州地区', '吕梁地区', '晋中市', '临汾地区', '运城地区');
cities['辽宁省']=new Array('沈阳市', '朝阳市', '阜新市', '铁岭市', '抚顺市', '本溪市', '辽阳市', '鞍山市', '丹东市', '大连市', '营口市', '盘锦市', '锦州市', '葫芦岛市');
cities['吉林省']=new Array('长春市', '白城市', '松原市', '吉林市', '四平市', '辽源市', '通化市', '白山市', '延边朝鲜族自治州');
function set_city(province, city)
{
var pv, cv;
var i, ii;
pv=provincevalue;
cv=cityvalue;
citylength=1;
if(pv=='0') return;
if(typeof(cities[pv])=='undefined') return;
for(i=0; i<cities[pv]length; i++)
{ ii = i+1;
cityoptions[ii] = new Option();
cityoptions[ii]text = cities[pv][i];
cityoptions[ii]value = cities[pv][i];
}}
function cha(){
if (documentmyformu_usernamevalue=="")
{
alert("用户名不能为空!");
}
else
{var str_cha = documentmyformu_usernamevalue;
locationhref="chaaspxstr=" + str_cha;
}}
由于百度限制了输入字数,所以上面的省市我都没写全,你自己去修改就可以了
我用的是jquery 页面触发js,
该js中的ajax 异步交互servlet
servlet获取ajax传过来的参数在数据库中根基参数查询出List结果
List循环编写成html格式(可以写成<select><option></option></select>等你想要的在页面中展示类型)的字符串返回到ajax的js接收结果中,
然后在指定位置吧该段html代码利用js添加就OK啊
注:仅仅是思路 你想想
--省级 provincial
create table provincial
(
provincialID int,
provincialName varchar(50),
primary key (provincialID)
)engine=INNODB default charset=gbk;
insert into provincial values(1,'北京市');
insert into provincial values(2,'天津市');
insert into provincial values(3,'上海市');
insert into provincial values(4,'重庆市');
insert into provincial values(5,'河北省');
insert into provincial values(6,'山西省');
insert into provincial values(7,'台湾省');
insert into provincial values(8,'辽宁省');
insert into provincial values(9,'吉林省');
insert into provincial values(10,'黑龙江省');
insert into provincial values(11,'江苏省');
insert into provincial values(12,'浙江省');
insert into provincial values(13,'安徽省');
insert into provincial values(14,'福建省');
insert into provincial values(15,'江西省');
insert into provincial values(16,'山东省');
insert into provincial values(17,'河南省');
insert into provincial values(18,'湖北省');
insert into provincial values(19,'湖南省');
insert into provincial values(20,'广东省');
insert into provincial values(21,'甘肃省');
insert into provincial values(22,'四川省');
insert into provincial values(23,'贵州省');
insert into provincial values(24,'海南省');
insert into provincial values(25,'云南省');
insert into provincial values(26,'青海省');
insert into provincial values(27,'陕西省');
insert into provincial values(28,'广西壮族自治区');
insert into provincial values(29,'西藏自治区');
insert into provincial values(30,'宁夏回族自治区');
insert into provincial values(31,'新疆维吾尔自治区');
insert into provincial values(32,'内蒙古自治区');
insert into provincial values(33,'澳门特别行政区');
insert into provincial values(34,'香港特别行政区');
select provincialID,provincialName from provincial;
--城市 city
create table city
(
cityID int not null,
cityName varchar(50) not null,
provincialID int not null,
primary key (cityID)
)engine=INNODB default charset=gbk; alter table city add constraint FK_pro_city_provincialID foreign key (provincialID)
references provincial (provincialID);
----------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
--插入各个省的城市数据
--4个直辖市
insert into city values(1,'北京市',1);
insert into city values(2,'天津市',2);
insert into city values(3,'上海市',3);
insert into city values(4,'重庆市',4);
--select from city where provincialID=4
----------------------------------------------------------------
--5河北省 11个地级市
insert into city values(5,'石家庄市',5);
insert into city values(6,'唐山市',5);
insert into city values(7,'秦皇岛市',5);
insert into city values(8,'邯郸市',5);
insert into city values(9,'邢台市',5);
insert into city values(10,'保定市',5);
insert into city values(11,'张家口市',5);
insert into city values(12,'承德市',5);
insert into city values(13,'沧州市',5);
insert into city values(14,'廊坊市',5);
insert into city values(15,'衡水市',5);
--select from city where provincialID=5 order by cityID
----------------------------------------------------------------
--6山西省 11个城市
insert into city values(16,'太原市',6);
insert into city values(17,'大同市',6);
insert into city values(18,'阳泉市',6);
insert into city values(19,'长治市',6);
insert into city values(20,'晋城市',6);
insert into city values(21,'朔州市',6);
insert into city values(22,'晋中市',6);
insert into city values(23,'运城市',6);
insert into city values(24,'忻州市',6);
insert into city values(25,'临汾市',6);
insert into city values(26,'吕梁市',6);
--select from city where provincialID=6 order by cityID
----------------------------------------------------------------
--7台湾省(台湾本岛和澎湖共设7市、16县,其中台北市和高雄市为“院辖市”,直属“行政院”,其余属台湾省;市下设区,县下设市(县辖市)、镇、乡,合称区市镇乡。);
insert into city values(27,'台北市',7);
insert into city values(28,'高雄市',7);
insert into city values(29,'基隆市',7);
insert into city values(30,'台中市',7);
insert into city values(31,'台南市',7);
insert into city values(32,'新竹市',7);
insert into city values(33,'嘉义市',7);
insert into city values(34,'台北县',7);
insert into city values(35,'宜兰县',7);
insert into city values(36,'桃园县',7);
insert into city values(37,'新竹县',7);
insert into city values(38,'苗栗县',7);
insert into city values(39,'台中县',7);
insert into city values(40,'彰化县',7);
insert into city values(41,'南投县',7);
insert into city values(42,'云林县',7);
insert into city values(43,'嘉义县',7);
insert into city values(44,'台南县',7);
insert into city values(45,'高雄县',7);
insert into city values(46,'屏东县',7);
insert into city values(47,'澎湖县',7);
insert into city values(48,'台东县',7);
insert into city values(49,'花莲县',7);
--select from city where provincialID=7 order by cityID
----------------------------------------------------------------
--8辽宁省 14个地级市
insert into city values(50,'沈阳市',8);
insert into city values(51,'大连市',8);
insert into city values(52,'鞍山市',8);
insert into city values(53,'抚顺市',8);
insert into city values(54,'本溪市',8);
insert into city values(55,'丹东市',8);
insert into city values(56,'锦州市',8);
insert into city values(57,'营口市',8);
insert into city values(58,'阜新市',8);
insert into city values(59,'辽阳市',8);
insert into city values(60,'盘锦市',8);
insert into city values(61,'铁岭市',8);
insert into city values(62,'朝阳市',8);
insert into city values(63,'葫芦岛市',8);
--select from city where provincialID=8 order by cityID
----------------------------------------------------------------
--9吉林省(2006年,辖:8个地级市、1个自治州;20个市辖区、20个县级市、17个县、3个自治县。);
insert into city values(64,'长春市',9);
insert into city values(65,'吉林市',9);
insert into city values(66,'四平市',9);
insert into city values(67,'辽源市',9);
insert into city values(68,'通化市',9);
insert into city values(69,'白山市',9);
insert into city values(70,'松原市',9);
insert into city values(71,'白城市',9);
insert into city values(72,'延边朝鲜族自治州',9);
--select from city where provincialID=9 order by cityID
----------------------------------------------------------------
--10黑龙江省(2006年,辖:12地级市、1地区;64市辖区、18县级市、45县、1自治县);
insert into city values(73,'哈尔滨市',10);
insert into city values(74,'齐齐哈尔市',10);
insert into city values(75,'鹤 岗 市',10);
insert into city values(76,'双鸭山市',10);
insert into city values(77,'鸡 西 市',10);
insert into city values(78,'大 庆 市',10);
insert into city values(79,'伊 春 市',10);
insert into city values(80,'牡丹江市',10);
insert into city values(81,'佳木斯市',10);
insert into city values(82,'七台河市',10);
insert into city values(83,'黑 河 市',10);
insert into city values(84,'绥 化 市',10);
insert into city values(85,'大兴安岭地区',10);
--select from city where provincialID=10 order by cityID
----------------------------------------------------------------
--11江苏省(2005年辖:13个地级市;54个市辖区、27个县级市、25个县);
insert into city values(86,'南京市',11);
insert into city values(87,'无锡市',11);
insert into city values(88,'徐州市',11);
insert into city values(89,'常州市',11);
insert into city values(90,'苏州市',11);
insert into city values(91,'南通市',11);
insert into city values(92,'连云港市',11);
insert into city values(93,'淮安市',11);
insert into city values(94,'盐城市',11);
insert into city values(95,'扬州市',11);
insert into city values(96,'镇江市',11);
insert into city values(97,'泰州市',11);
insert into city values(98,'宿迁市',11);
--select from city where provincialID=11 order by cityID
----------------------------------------------------------------
--12浙江省(2006年,辖:11个地级市;32个市辖区、22个县级市、35个县、1个自治县。);
insert into city values(99,'杭州市',12);
insert into city values(100,'宁波市',12);
insert into city values(101,'温州市',12);
insert into city values(102,'嘉兴市',12);
insert into city values(103,'湖州市',12);
insert into city values(104,'绍兴市',12);
insert into city values(105,'金华市',12);
insert into city values(106,'衢州市',12);
insert into city values(107,'舟山市',12);
insert into city values(108,'台州市',12);
insert into city values(109,'丽水市',12);
--select from city where provincialID=12 order by cityID
---------------------------------------------------------------- 没有写完, 写不下了,你加我! 775790318
以上就是关于.net省市二级联动中如何向数据库中添加省市全部的内容,包括:.net省市二级联动中如何向数据库中添加省市、省市区 地址联动 数据怎么创建、如何获取省市联动的值并写入数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)