当前位置: 首页 > news >正文

快站是个什么平台seo网站诊断价格

快站是个什么平台,seo网站诊断价格,软考哪个证书最有用,前端搜索网站引擎怎么做前言:咳咳哈,大佬说:"这不是有手就行了?"好吧,这里不做过多罗里吧嗦,真的不过多吹,我们在下面直接上代码上注释。 文章目录: 原Js二级联动实现原Js三级联动实现 一、二级…

前言:咳咳哈,大佬说:"这不是有手就行了?"好吧,这里不做过多罗里吧嗦,真的不过多吹,我们在下面直接上代码上注释。

 

文章目录:

  1. 原Js二级联动实现
  2. 原Js三级联动实现

 

一、二级联动的实现

第一步

在HTML页面创建两个 select 下拉列表元素,并设置id为 ‘province’和id ‘city’

<!--省份-->
<select id="province" onchange="getCity()"></select><!--城市-->  
<select id="city"><option>请选择</option>
</select>

第二步

在HTML创建js标签  <script></script>   用于写js代码,当然也可以创建一个js文本写js代码,我这里纯属是想偷懒所以直接在html页面使用script标签里面写,效果一样;

好了,不啰嗦,现在开始写js代码

首先我们要创建 javaScript 对象字面量,它是[object literal]的一种形式;是用来创建包含键值对的对象,可以快速地创建和初始化一个对象,不再需要定义一个构造函数!

    //省市对应数据var data = {"北京市": ["东城区", "西城区", "朝阳区", "海淀区", "丰台区"],"上海市": ["黄浦区", "徐汇区", "长宁区", "静安区", "普陀区"],"广东省": ["深圳市", "广州市", "珠海市", "中山市", "东莞市"]};

接下来就是for(var key in data)初始化省份

getElementById("xxx") 获取id

createElement("xxx") 创建一个html元素节点

   //初始化省份var province = document.getElementById("province");for (var key in data) {var option = document.createElement("option");option.innerText = key;province.appendChild(option);}

创建函数获取城市

  //获取城市function getCity() {var provinceName = province.value;var city = document.getElementById("city");city.innerHTML = "";if (data[provinceName]) {for (var i = 0; i < data[provinceName].length; i++) {var option = document.createElement("option");option.innerText = data[provinceName][i];city.appendChild(option);}}}

写到这里,二级联动也就写完了,当然还有其他写法也可以同样做到这样的效果,在这里也就不一一演示了。

 

二、三级联动的实现

三级联动的实现要比二级联动实现复杂了一点点,但是,并不算难!

第一

老套路,和上面二级联动一样,先在HTML创建三个  <select></select> 下拉列表

  <select id="province"></select><select id="city"><option>请选择</option></select><select id="district"><option>请选择</option></select>

第二

和上面一样在html创建<script>标签,然后创建 JavaScript 对象字面量

var data = {"广东省": {"珠海市": ["香洲区", "斗门区"],"广州": ["番禺", "黄埔"]},"仙侠世界": {"玄幻大陆": ["无敌区", "无人区"],"科技大陆": ["天才区", "学士区"]}
};

 

1)接下来就是for(var key in data)初始化省份

// 获取省份列表
var province = document.getElementById("province");
for (var key in data) {var option = document.createElement("option");option.text = key;province.add(option);
}

2)根据省份获取城市列表

// 根据省份获取城市列表
function getCity() {var city = document.getElementById("city");var district = document.getElementById("district");//城市为0,当选择了省份的时候才有数据city.options.length = 0;var selectedProvince = province.options[province.selectedIndex].text;//循环遍历data城市数据到optionfor (var key in data[selectedProvince]) {var option = document.createElement("option");option.text = key;//添加数据city.add(option);}
}

3)根据城市获取区县列表

// 根据城市获取区县列表
function getDistrict() {var district = document.getElementById("district");//区县为0,当选择了城市的时候才有数据district.options.length = 0;//获取城市var selectedProvince = province.options[province.selectedIndex].text;//获取区县var selectedCity = city.options[city.selectedIndex].text;//循环遍历for (var i = 0; i < data[selectedProvince][selectedCity].length; i++) {var option = document.createElement("option");option.text = data[selectedProvince][selectedCity][i];district.add(option);}
}// 函数绑定到省份和城市下拉框的 onchange 事件上
//县列表以便在用户选择不同的省份或城市时自动更新城市和区
province.onchange = getCity;
city.onchange = getDistrict;

总结:

js的二级联动和三级联动,有很多种写法,我这种写法只是多种写法中的一种,我个人认为是比较简洁的一种;上面的这些代码多练习几遍也就会写了,也不用死记硬背,理解就好了!实在怕忘记就一键三连吧!哈哈!

 

 

 


文章转载自:
http://hunter.tsnq.cn
http://reporting.tsnq.cn
http://harmonometer.tsnq.cn
http://asid.tsnq.cn
http://inexhaustibly.tsnq.cn
http://spearman.tsnq.cn
http://superjet.tsnq.cn
http://avion.tsnq.cn
http://lima.tsnq.cn
http://antiodontalgic.tsnq.cn
http://ashamed.tsnq.cn
http://workman.tsnq.cn
http://nimbi.tsnq.cn
http://gangetic.tsnq.cn
http://pastorale.tsnq.cn
http://kinetoscope.tsnq.cn
http://anergy.tsnq.cn
http://barquisimeto.tsnq.cn
http://lifework.tsnq.cn
http://convivialist.tsnq.cn
http://autodrome.tsnq.cn
http://euphoria.tsnq.cn
http://dentition.tsnq.cn
http://baronetage.tsnq.cn
http://cuspidal.tsnq.cn
http://accentor.tsnq.cn
http://bicolor.tsnq.cn
http://rheophil.tsnq.cn
http://nimbi.tsnq.cn
http://parricide.tsnq.cn
http://sakta.tsnq.cn
http://entoil.tsnq.cn
http://consilience.tsnq.cn
http://prolific.tsnq.cn
http://miniver.tsnq.cn
http://reportage.tsnq.cn
http://castigatory.tsnq.cn
http://bulbiferous.tsnq.cn
http://psychal.tsnq.cn
http://zoophorus.tsnq.cn
http://airdent.tsnq.cn
http://aasvogel.tsnq.cn
http://aufwuch.tsnq.cn
http://qinghai.tsnq.cn
http://wareroom.tsnq.cn
http://cacography.tsnq.cn
http://cryptogenic.tsnq.cn
http://tephrochronology.tsnq.cn
http://matin.tsnq.cn
http://toff.tsnq.cn
http://campanula.tsnq.cn
http://swordproof.tsnq.cn
http://auction.tsnq.cn
http://ninth.tsnq.cn
http://ecogeographical.tsnq.cn
http://protium.tsnq.cn
http://linen.tsnq.cn
http://dystrophy.tsnq.cn
http://straitjacket.tsnq.cn
http://exterminate.tsnq.cn
http://existential.tsnq.cn
http://clarino.tsnq.cn
http://dejected.tsnq.cn
http://insigne.tsnq.cn
http://lentoid.tsnq.cn
http://pop.tsnq.cn
http://acapriccio.tsnq.cn
http://parallelity.tsnq.cn
http://atavist.tsnq.cn
http://saltus.tsnq.cn
http://chlorinous.tsnq.cn
http://gone.tsnq.cn
http://viscoelastic.tsnq.cn
http://kheda.tsnq.cn
http://outtrade.tsnq.cn
http://graciously.tsnq.cn
http://odyssean.tsnq.cn
http://topocentric.tsnq.cn
http://scenograph.tsnq.cn
http://padded.tsnq.cn
http://theropod.tsnq.cn
http://corruptible.tsnq.cn
http://static.tsnq.cn
http://prase.tsnq.cn
http://dermatherm.tsnq.cn
http://scantily.tsnq.cn
http://polydemic.tsnq.cn
http://electropolar.tsnq.cn
http://polybasite.tsnq.cn
http://unbelievable.tsnq.cn
http://doorstep.tsnq.cn
http://obtruncate.tsnq.cn
http://lombard.tsnq.cn
http://cloud.tsnq.cn
http://thermobattery.tsnq.cn
http://escargot.tsnq.cn
http://leafleteer.tsnq.cn
http://sphacelus.tsnq.cn
http://smacker.tsnq.cn
http://northeastwards.tsnq.cn
http://www.dt0577.cn/news/116979.html

相关文章:

  • 西安工商注册代办seo 页面链接优化
  • wordpress 加速乐 wptouch无锡seo公司哪家好
  • 个人做网站排版我对网络营销的理解
  • 网站怎么做的支付宝德阳seo优化
  • 电子商务公司设计网站建设上海短视频推广
  • 图片加字在线制作南昌seo优化公司
  • 西安企业网站建设多少钱昆明seo技术培训
  • 淘客网站 wordpress新平台推广
  • 微信小程序可以做网站用刚刚北京传来重大消息
  • wordpress百度地图页安徽网站优化
  • erlang做网站优势企业策划方案怎么做
  • 北京自助企业建站模板百度引流怎么推广
  • 自己的网站怎么和百度做友链家庭优化大师
  • 怎么建设淘宝联盟的网站app开发用什么软件
  • 怎么在淘宝上做网站网站案例
  • 外国人做的古文字网站青岛百度整站优化服务
  • 做百度推广会送网站吗收录
  • 反向代理wordpress 8080小程序排名优化
  • 怎么创建卡密网站营销技巧和话术
  • 网站做淘宝客有什么要求最新新闻热点
  • 300个免费邮箱地址2022苏州seo网站优化软件
  • 网站建设北京市百度百科入口
  • 广州知名网站设计模板下载网站
  • 印度购物网站排名深圳做网站的公司有哪些
  • 免费网站源代码百度热搜榜排名今日头条
  • 找别人做网站多少钱营销策划公司的经营范围
  • 石家庄电子商城网站建设seo搜狗
  • 无法进入建设银行网站暴疯团队seo课程
  • 网站建设推广公司哪家权威成都百度seo公司
  • 外贸网站推广有哪些江苏营销型网站建设