/**
* @author wangxiang
* @email:flyxiang228@gmail.com
* @copyright privite
*/
var countryProvcity = function(data){
this.data = data;
}
countryProvcity.prototype = {
init: function (){
var _t = this;
var _d = this.data;
_d.cid = _d.cid?_d.cid:"cid"; //country id
_d.pid = _d.pid ? _d.pid : "pid";//city id
_d.pnum = _d.pnum ? _d.pnum : "pnum";//country number
//_d.cnum = _d.cnum ? _d.cnum : "";//city number
_d.box = _d.box ? _d.box : "box"; //container id
var provinces = {
"United states":1000840000,"Canada":1001124000,"Afghanistan":3040004000,"Albania":2200008000,"Algeria":5010012000,"American Samoa":3070016000,"Andorra":2100020000,"Angola":5020024000,"Anguilla":6010660000,"Antigua and Barbuda":6010028000,"Argentina":6030032000,"Armenia":3040051000,"Aruba":6010533000,"Australia":3010036000,"Austria":2100040000,"Azerbaijan":3040031000,"Bahamas":6010044000,"Bahrain":4000048000,"Bangladesh":3050050000,"Barbados":6010052000,"Belarus":2200112000,"Belgium":2100056000,"Belize":6020084000,"Benin":5020204000,"Bermuda":6010060000,"Bhutan":3050064000,"Bolivia":6030068000,"Bosnia and Herzegovina":2200070000,"Botswana":5020072000,"Brazil":6030076000,"British Virgin Islands":6010092000,"Brunei":3060096000,"Bulgaria":2200100000,"Burkina Faso":5020854000,"Burundi":5020108000,"C?te d'Ivoire":5020384000,
"Cambodia":3060116000,"Cameroon":5020120000,"Cape Verde":5020132000,"Cayman Islands":6010136000,"Central African Republic":5020140000,"Chad":5020148000,"Chile":6030152000,"China":3030156000,"Colombia":6030170000,"Comoros":5020174000,"Congo":5020178000,"Cook Islands":3070184000,"Costa Rica":6020188000,"Croatia":2200191000,"Cuba":6010192000,"Cyprus":2100196000,"Czech Republic":2200203000,"Democratic Republic of Congo":5020180000,"Denmark":2100208000,"Djibouti":5020262000,"Dominica":6010212000,"Dominican Republic":6010214000,"East Timor":3060626000,"Ecuador":6030218000,"Egypt":5010818000,"El Salvador":6020222000,"Equatorial Guinea":5020226000,"Eritrea":5020232000,"Estonia":2200233000,"Ethiopia":5020231000,"Falkland Islands":6030238000,"Federated state1s of Micronesia":3070583000,
"Fiji":3070242000,"Finland":2100246000,"France":2100250000,"French Guiana":6030254000,"French Polynesia":3070258000,"Gabon":5020266000,"Gambia":5020270000,"Georgia":3040239000,"Germany":2100276000,"Ghana":5020288000,"Gibraltar":2100292000,"Greece":2100300000,"Greenland":2104304000,"Grenada":6010308000,"Guadeloupe":6010312000,"Guam":3070316000,"Guatemala":6020320000,"Guinea":5020324000,"Guinea-Bissau":5020624000,"Guyana":6030328000,"Haiti":6010332000,"Honduras":6020340000,"Hong Kong":3030344000,"Hungary":2200348000,"Iceland":2100352000,"India":3050356000,"Indonesia":3060360000,"Iran":3040364000,"Iraq":4000368000,"Ireland":2100372000,"Israel":4000376000,"Italy":2100380000,"Jamaica":6010388000,"Japan":3020392000,"Jordan":4000400000,"Kazakhstan":3040398000,"Kenya":5020404000,"Kiribati":3070296000,"Korea":3020410000,
"Kuwait":4000414000,"Kyrgyzstan":3040417000,"Laos":3060418000,"Latvia":2200428000,"Lebanon":4000422000,"Lesotho":5020426000,"Liberia":5020430000,"Libya":5010434000,"Liechtenstein":2100438000,"Lithuania":2200440000,"Luxembourg":2100442000,"Macau":3030446000,"Macedonia":2200807000,"Madagascar":5020450000,"Malawi":5020454000,"Malaysia":3060458000,"Maldives":3050462000,"Mali":5020466000,"Malta":2200470000,"Marshall Islands":3070584000,"Martinique":6010474000,"Mauritania":5020478000,"Mauritius":5020480000,"Mexico":6020484000,"Moldova":2200498000,"Monaco":2100492000,"Mongolia":3020496000,"Montserrat":6010500000,"Morocco":5010504000,"Mozambique":5020508000,"Myanmar":3050104000,"Namibia":5020516000,"Nauru":3070520000,"Nepal":3050524000,"Netherlands Antilles":6010530000,"Netherlands":2100528000,"New Caledonia":3070540000,
"New Zealand":3010554000,"Nicaragua":6020558000,"Niger":5020562000,"Nigeria":5020566000,"North Korea":3020408000,"Northern Mariana Islands":3070580000,"Norway":2100578000,"Oman":4000512000,"Pakistan":3050586000,"Palau":3070585000,"Panama":6020591000,"Papua New Guinea":3070598000,"Paraguay":6030600000,"Peru":6030604000,"Philippines":3060608000,"Poland":2200616000,"Portugal":2100620000,"Puerto Rico":6010630000,"Qatar":4000634000,"Romania":2200642000,"Russia":2200643000,"Rwanda":5020646000,"Saint Kitts & Nevis":6010659000,"Saint Lucia":6010662000,"Saint Vincent and The Grenadines":6010670000,"Samoa":3070882000,"San Marino":2100674000,"Saudi Arabia":4000682000,"Senegal":5020686000,"Serbia":2200688000,"Seychelles":5020690000,"Sierra Leone":5020694000,"Singapore":3060702000,"Slovakia":2200703000,"Slovenia":2200705000,"Solomon Islands":3070090000,
"Somalia":5020706000,"South Africa":5020710000,"Spain":2100724000,"Sri Lanka":3050144000,"Sudan":5020736000,"Suriname":6030740000,"Swaziland":5020748000,"Sweden":2100752000,"Switzerland":2100756000,"Syria":4000760000,"Taiwan":3030158000,"Tajikistan":3040762000,"Tanzania":5020834000,"Thailand":3060764000,"Togo":5020768000,"Tonga":3070776000,"Trinidad and Tobago":6010780000,"Tunisia":5010504000,"Turkey":4000792000,"Turkmenistan":3040795000,"Turks and Caicos Islands":6010796000,"Tuvalu":3070798000,"US Virgin Islands":6010850000,"Uganda":5020800000,"Ukraine":2200804000,"United Arab Emirates":4000784000,"United Kingdom":2100826000,"Uruguay":6030858000,"Uzbekistan":3040860000,"Vanuatu":3070548000,"Vatican":2100336000,"Venezuela":6030862000,"Vietnam":3060704000,"Yemen":4000887000,"Zambia":5020894000,"Zimbabwe":5020716000
};
var selObj = document.createElement("select");
var inpObj = document.createElement("input");
var inpId = document.createAttribute("id");
var inpName = document.createAttribute("name");
var inpClass = document.createAttribute("class");
var inpType = document.createAttribute("type");
inpId.value="plain";
inpName.value="state";
inpType.value = "text";
inpClass.value="plain_hidden";
inpObj.setAttributeNode(inpId);
inpObj.setAttributeNode(inpName);
inpObj.setAttributeNode(inpType);
selObj.name = _d.cid;
selObj.id = _d.cid;
selObj.onchange = function() {
_t._(_d.pid) ? _t._('state1').removeChild(_t._(_d.pid)) : '';
return _t._setcity(_d.cid, _d.pid, _d.box);
};
this._(_d.box).appendChild(selObj);
_t._(_d.cid).className = "select_style3_100 m_right_10";//set country select class
_t._("state1").appendChild(inpObj);
selObj.options[0] = new Option("Select Country", "");
var j = 1;
for(i in provinces) {
selObj.options[j] = new Option(i, provinces[i]);
j++;
}
if(_d.pnum != "")
{
typeof(_d.cnum) == 'string' ? inpObj.setAttribute("value",_d.cnum) : '';
inpObj.setAttributeNode(inpClass);
_t._initprovcity(_d.cid, _d.pnum);
return;
}
else{
inpClass.value="plain_show";
inpObj.setAttributeNode(inpClass);
}
},
_: function (id){
if(document.getElementById(id)){
return document.getElementById(id);
}
},
_setcity: function (provinceid, cityid,boxid) {
var province = parseFloat(this._(provinceid).value);
switch (province) {
case 1000840000 :
var cityOptions = {
"Alabama":1000840301,"Alaska":1000840802,"Arizona":1000840704,"Arkansas":1000840305,"California":1000840806,"Colorado":1000840608,"Connecticut":1000840109,"Delaware":1000840210,"District of Columbia":1000840211,"Florida":1000840312,
"Georgia":1000840313,"Hawaii":1000840815,"Idaho":1000840616,"Illinois":1000840417,"Indiana":1000840418,"Iowa":1000840519,"Kansas":1000840520,"Kentucky":1000840421,"Louisiana":1000840322,"Maine":1000840123,"Maryland":1000840224,"Massachusetts":1000840125,
"Michigan":1000840426,"Minnesota":1000840427,"Mississippi":1000840328,"Missouri":1000840529,"Montana":1000840630,"Nebraska":1000840531,"Nevada":1000840732,"New Hampshire":1000840133,"New Jersey":1000840134,"New Mexico":1000840735,"New York":1000840136,
"North Carolina":1000840237,"North Dakota":1000840538,"Ohio":1000840439,"Oklahoma":1000840540,"Oregon":1000840841,"Pennsylvania":1000840442,"Rhode Island":1000840144,"South Carolina":1000840345,"South Dakota":1000840546,"Tennessee":1000840347,"Texas":1000840748,
"Utah":1000840649,"Vermont":1000840150,"Virginia":1000840251,"Washington":1000840853,"West Virginia":1000840254,"Wisconsin":1000840455,"Wyoming":1000840656
};
break;
case 1001124000 :
var cityOptions = {
"Alberta":1001124002,
"British Columbia":1001124008,
"Manitoba":1001124012,
"New Brunswick":1001124018,
"Newfoundland and Labrador":1001124022,
"Northwest Territories":1001124028,
"Nova Scotia":1001124032,
"Nunavut":1001124038,
"Ontario":1001124042,
"Prince Edward Island":1001124048,
"Quebec":1001124052,
"Saskatchewan":1001124058,
"Yukon Territory":1001124062
};
break;
default:
var cityOptions = null;
break;
}
if(cityOptions == null && this._(cityid))
{
this._("state1").removeChild(this._(cityid));
this._("plain").setAttribute("name","state");
this._("plain").setAttribute("value","");
this._("plain").className = "plain_show";
return;
}else if (cityOptions == null && !this._(cityid))
{
this._("plain").setAttribute("name","state");
this._("plain").className = "plain_show";
return;
}
else if(!this._(cityid))
{
var selObj = document.createElement("select");
selObj.name = cityid;
selObj.id = cityid;
this._("plain").className = "plain_hidden";
this._("plain").setAttribute("name","testing");
this._("state1").appendChild(selObj);
this._("state").className = "select_style3_100 m_right_10";
}
var cityObject = this._(cityid);
var j = 0;
for(i in cityOptions){
cityObject.options[j] = new Option(i,cityOptions[i]);
j++;
}
if(this.data.cnum != null && typeof(this.data.cnum) == "number"){
for(var i = 0; i < cityObject.options.length; i++) {
if (cityObject.options[i].value == this.data.cnum) {
cityObject.selectedIndex = i;
break;
}
}
}
},
_initprovcity: function (provinceid, province) {
var provObject = this._(provinceid);
for(var i = 0; i < provObject.options.length; i++) {
if (provObject.options[i].value == province) {
provObject.selectedIndex = i;
break;
}
}
this._setcity(provinceid, this.data.pid);
}
}
<html>
<style type="text/css">
#selectbox{position:relative;}
.plain_show{display:block;}
.plain_hidden{display:none;}
</style>
<head>
<script type="text/javascript" src="selectcity_n.js"></script>
</head>
<body>
<div id="country"><label for="">Country</label></div>
dsafsafasfdasdfasdfasdfasd
<div id="state1"><label for="">State Province</label></div>
<script type="text/javascript">
var countryProvcity = new countryProvcity({cid:'province', pid:'state', pnum:'2100246000', cnum:'', box:'country'});
countryProvcity.init();
</script>
</body>
</html>
分享到:
相关推荐
本篇文章将深入探讨如何使用JavaScript实现类似Windows系统的树导航菜单。 首先,理解树形结构的基本概念是至关重要的。树形结构是一种数据结构,其中的数据项按照层级关系组织,每个数据项称为节点,每个节点可以...
JavaScript是网页制作中不可或缺的...随着学习的深入,你可以创建更复杂的交互式网页,实现表单验证、动态效果、Ajax通信等功能。继续探索JavaScript,你会发现它是一个强大且灵活的工具,能够极大地提升网页用户体验。
CSS还可以用来实现响应式设计,让网页在不同设备和屏幕尺寸上都能良好展示。此外,CSS选择器是其核心概念,允许精准定位并操作特定的HTML元素。 JavaScript是一种强大的编程语言,它赋予网页动态交互的能力。通过...
统计字符出现的次数 Java、Python、Shell、JavaScript 实现 Statistical Character Appearance Times in Java, Python, Shell, and JavaScript) 统计字符出现的次数是指在一个字符串中统计每个字符出现的次数,这...
通过使用不同的标签,如`<h1>`(标题)、`<p>`(段落)、`<img>`(图像)和`<a>`(链接),开发者可以创建出层次清晰、内容丰富的网页。HTML5的出现更是增加了多媒体支持,如音频和视频,使网页内容更加多样化。 ...
javacript 经典,入门与复习的最佳资料,让您最短的时间学到最多的内容!
javacript控制文本输入限制javacript控制文本输入限制javacript控制文本输入限制
通过检测窗口尺寸变化(`resize`事件)并调整元素样式,实现不同设备上的适配。 9. **滚动监听**:当页面滚动到特定位置时触发某些效果,如固定头部、加载更多内容等。可以使用`window.onscroll`事件和`...
javacript新浪图片切换效果,操作简单
【C#与JavaScript数据交互】 在Web开发中,C#(通常用于服务器端)和JavaScript(主要用于客户端)的交互是常见的需求。这两种语言虽然在不同的环境中运行,但...在实际应用中,根据项目需求和场景选择合适的方法。
node-smb-server, SMB文件共享协议的100%位JavaScript实现 用于 Node.js的 SMB服务器 Overwiewnode-smb-server 是 smb/cifs文件共享协议的开源JavaScript实现。一些亮点:纯 JavaScript完全可以配置/自定义可以扩展...
5. 兼容性处理:由于JavaScript引擎和浏览器实现的差异,我们需要确保代码在不同浏览器上都能正常运行。对于较老的浏览器,如IE,可能需要使用像jQuery这样的库来帮助解决兼容性问题,或者采用特征检测和渐进增强的...
Minio是GlusterFS创始人之一Anand Babu Periasamy发布新的开源项目。Minio兼容Amason的S3分布式对象存储项目,采用Golang实现,客户端支持Java,Python,Javacript, Golang语言
本篇文章将深入探讨Android中Java与JavaScript的交互机制,以及如何实现它们之间的调用。 首先,Java作为Android平台的主要开发语言,为开发者提供了丰富的API和强大的性能支持。它是一种静态类型语言,强调类型...
这是 博客 https://blog.csdn.net/qq_37188778/article/details/84818597所用的代码、其中arcgis for javacript 请大家自行下载引入
在本项目中,我们关注的是使用JavaScript实现的“进度条”功能,这是一种用户界面元素,可以展示任务或数据加载的状态,为用户提供实时反馈。 在JavaScript中创建进度条涉及到以下几个关键知识点: 1. HTML结构:...
JavaScript是一种广泛应用于网页和网络应用开发的脚本语言,它主要负责实现客户端的交互功能。在JavaScript中,弹出窗口是常见的用户交互手段,能够显示警告、确认或自定义信息。这篇博客“比较完备的JavaScript弹出...
5. 实现颜色数组:最终,根据以上计算得到一个颜色数组(colorArray),这个数组的每个元素代表一种渐变的颜色值。通过循环遍历这个数组,可以实现颜色的连续渐变效果。 6. 频率调节:在实际应用中,可以调节渐变...