最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

原生js實(shí)現(xiàn)html手機(jī)端城市列表索引選擇城市

 更新時(shí)間:2020年06月24日 15:38:18   作者:Jeslie-He  
這篇文章主要為大家詳細(xì)介紹了原生js實(shí)現(xiàn)html手機(jī)端城市列表索引選擇城市,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)手機(jī)端城市列表索引選擇城市的具體代碼,供大家參考,具體內(nèi)容如下

html部分:

<div class="cityPage">
 <div class="cityContent">
 <div class="inputBox">
 <input type="text" placeholder="中文 / 拼音首字母" id="findcityInp">
 </div>
 <div class="localCity">定位城市</div>
 <div class="cityname">上海市</div>
 </div>
 <div id='list'>
 <section id="sectionBox"></section>
 <nav id="navBar"></nav>
 </div>
 <div class="letterBox"></div>
</div>

css部分:

*{
 margin: 0;
 padding: 0;
 list-style: none;
}
html{
 font-size: 12px;
}
body {
 background-color: #f5f5f5;
 font-family: 'PingFang SC Regular', 'PingFang SC';
 width: 100%;
 height: 100%;
 min-width: 320px;
 max-width: 480px;
 position: relative;
}

.cityPage {
 width: 100%;
 height: 100%;
 /* border: 1px solid black; */
 position: relative;
 top: 0;
 display: flex;
 flex-direction: column;
 /* justify-content: center; */
}

.cityContent {
 width: 100%;
 height: 140px;
 /* border: 1px solid black; */
 background: #f7f7f9;
 position: fixed;
 z-index: 9999;
 top: 0;

}

.inputBox input {
 width: 90%;
 height: 30px;
 border: 1px solid rgb(215, 215, 215);
 outline: none;
 background: #fff;
 margin-left: 4%;
 border-radius: 4px;
 padding-left: 4px;
 color: #9e9e9e;
 font-size: 14px;
 margin-bottom: 16px;
 margin-top: 14px;

}

.localCity {
 color: #333;
 font-size: 13px;
 font-weight: bold;
 margin-left: 4.5%;
 margin-bottom: 16px;
}

.cityname {
 font-size: 13px;
 margin-left: 4.5%;
 margin-bottom: 16px;
}

#list {
 font-size: 13px;
 position: fixed;
 height: 100%;
 top: 140px;
 width: 100%;
 overflow: scroll;
 font-size: 15px;
 /* margin-bottom: 140px; */
 /* bottom: 200px; */
}

#list>section {
 overflow-y: auto;
 height: 100%;
 margin-bottom: 140px;
}

#list>section>dl>dt {
 background: #f7f7f9;
 color: #999;
 height: 40px;
 line-height: 40px;
 padding-left: 15px;
}

#list>section>dl>dd {
 color: #333;
 line-height: 40px;
 padding-left: 15px;
 position: relative;
 background-color: #fff;
}

#list>section>dl>dd:after {
 content: '';
 position: absolute;
 left: 0;
 bottom: 1px;
 width: 100%;
 height: 1px;
 background-color: #c8c7cc;
 transform: scaleY(.5);
 -webkit-transform: scaleY(.5);
}

#list>section>dl>dd:last-of-type:after {
 display: none;
}

#navBar {
 position: fixed;
 width: 26px;
 height: 50%;
 right: 0;
 z-index: 30;
 top: 50%;
 display: flex;
 flex-direction: column;
 margin-top: -25%;
 /* text-align: center; */
}

#navBar.active {
 background: rgba(211, 211, 211, .6);
}

#navBar>div {
 text-align: center;
 display: block;
 text-decoration: none;
 /* height: 4.166%;
 line-height: 100%; */
 color: #333;
 font-size: 13px;
 flex: 1;
}
.letterBox{
 width: 40px;
 height: 40px;
 background:#9f9f9f;
 opacity: .5;
 position: fixed;
 top: 50%;
 left: 50%;
 margin-top: -25px;
 margin-left: -25px;
 text-align: center;
 line-height: 40px;
 color: #fff;
 display: none;
}

js部分:

$(function () { 
 initCities(cityData);
 clickAction()

 //輸入城市查詢
 var key = false;
 $('#findcityInp').on('compositionstart', function () {
 key = true;
 console.log('不搜索')
 });
 $('#findcityInp').on('compositionend', function (e) {
 var keyWord = $.trim(e.target.value);
 if(keyWord.length>0){
 var result = findCity(keyWord, cityData);
 initCities(result);
 bindEvent();

 }else{
 initCities(cityData);
 bindEvent();
 
 }
 });

 $('#findcityInp').on('change', function (e) {
 var keyWord = $.trim(e.target.value);
 console.log(keyWord)
 var result = findCity(keyWord, cityData);
 // console.log(result)
 initCities(result)

 });
 //城市查詢
 function findCity(keyWord, data) {
 if (!(data instanceof Array)) return;

 var reg = new RegExp(keyWord);
 var arr = [];
 var obj ={
  name:'',
  cities:[]
 }
 if(keyWord.length>0 && checkCh(keyWord)==false){
  data.forEach((item, index) => {
  item.cities.forEach((childItem, childIndex) => {
   if (childItem.tags.match(reg)) {
   obj.name = childItem.tags[0];
   obj.cities.push(childItem)
   arr=[obj]
   }
  })
  })
 }else if(keyWord.length ==1 && checkCh(keyWord)==true){
  data.forEach((item,index)=>{
  if(item.name == keyWord){
   // console.log(item)
   arr.push(item)
  }
  })
 }
 else{
  arr = data
 }
 return arr;
 }
 

function checkCh(str){
 var RegExp = /^[a-zA-Z]{1}$/;
 return RegExp.test(str);  
}
//點(diǎn)擊右邊描點(diǎn)
function toTarget(tag){
 var text = $(tag).text();
 location.href = "#"+text;
 $('.letterBox').html(text);
$('.letterBox').show()
setTimeout(function(){
 $('.letterBox').hide()
},1000)

}
//初始化城市列表
function initCities(cityData) {
 var g = "";
 $('section').html('');
 $('nav').html('')
 cityData.forEach((item, index) => {
  g += "<dl id=" + item.name + "><dt>" + item.name + "</dt>";
  item.cities.forEach((citiesItem, citiesIndex) => {
   g += "<dd data-id=" + citiesItem.cityid + " data-name=" + citiesItem.name + " class='list' οnclick='clickAction()'>" + citiesItem.name + "</dd>"
  })
  g += "</dl>"
 })
 $('section').append(g);

 var g = $('nav').height() / 26;
 var f = '';

 cityData.forEach((item, index) => {
  // f += '<a href="#' + item.name + '" rel="external nofollow" style="height:' + g + "px;line-height:" + g + 'px">' + item.name + "</a>"
  f+=`<div οnclick="toTarget(this)" style="height:${g}px;line-height:${g}px">${item.name}</div>`
 })
 $('nav').append(f);
}



//點(diǎn)擊城市列表某城市
function clickAction(){
 $('.list').click(function (e) {
 console.log(e.target.getAttribute('data-name'))
 })
} 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • javascript實(shí)現(xiàn)圖片左右滾動(dòng)效果【可自動(dòng)滾動(dòng),有左右按鈕】

    javascript實(shí)現(xiàn)圖片左右滾動(dòng)效果【可自動(dòng)滾動(dòng),有左右按鈕】

    這篇文章主要介紹了javascript實(shí)現(xiàn)圖片左右滾動(dòng)效果,可實(shí)現(xiàn)自動(dòng)滾動(dòng),帶有左右按鈕功能,基于插件scrollPic.js實(shí)現(xiàn),附帶了相應(yīng)的demo源碼供讀者下載參考,需要的朋友可以參考下
    2016-09-09
  • js實(shí)現(xiàn)卡片式項(xiàng)目管理界面UI設(shè)計(jì)效果

    js實(shí)現(xiàn)卡片式項(xiàng)目管理界面UI設(shè)計(jì)效果

    這篇文章主要介紹了js實(shí)現(xiàn)卡片式項(xiàng)目管理界面UI設(shè)計(jì)效果,該UI設(shè)計(jì)中,將各個(gè)項(xiàng)目以卡片的方式堆疊排列在屏幕上,當(dāng)點(diǎn)擊了其中的某個(gè)項(xiàng)目的時(shí)候,該項(xiàng)目圖片會(huì)全屏放大,向下滾動(dòng)鼠標(biāo)可以看到該項(xiàng)目的介紹信息,需要的朋友可以參考下
    2015-12-12
  • iframe與主框架跨域相互訪問實(shí)現(xiàn)方法

    iframe與主框架跨域相互訪問實(shí)現(xiàn)方法

    今天正好需要用到iframe 與主框架相互訪問的實(shí)現(xiàn)方法,正好看到了這篇文章,確實(shí)不錯(cuò),特分享一下,需要的朋友可以參考下
    2017-09-09
  • JavaScript Promise與async/await作用詳細(xì)講解

    JavaScript Promise與async/await作用詳細(xì)講解

    Promise是異步編程的一種解決方案:從語(yǔ)法上講,promise是一個(gè)對(duì)象,從它可以獲取異步操作的消息;從本意上講,它是承諾,承諾它過一段時(shí)間會(huì)給你一個(gè)結(jié)果
    2023-01-01
  • 前端解析包含圖片的excel文件完整步驟及代碼示例

    前端解析包含圖片的excel文件完整步驟及代碼示例

    作為一名開發(fā)者,大家在開發(fā)過程中是不是經(jīng)常遇到各種各樣的文件,比如xlsx、word、ppt等辦公類型的文件格式,這篇文章主要給大家介紹了關(guān)于前端解析包含圖片的excel文件的相關(guān)資料,需要的朋友可以參考下
    2024-07-07
  • JavaScript中閉包的寫法和作用詳解

    JavaScript中閉包的寫法和作用詳解

    本文給大家介紹javascript中的閉包,包括對(duì)js閉包概念的理解,閉包的幾種寫法和用法,閉包的主要作用,閉包與this對(duì)象,閉包與內(nèi)存泄露及使用閉包的注意點(diǎn)相關(guān)知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧
    2016-06-06
  • 聊一聊對(duì)js包裝對(duì)象的理解

    聊一聊對(duì)js包裝對(duì)象的理解

    JavaScript中的基本類型通過自動(dòng)裝箱和拆箱機(jī)制,可以臨時(shí)轉(zhuǎn)換為對(duì)應(yīng)的包裝對(duì)象,以訪問屬性和方法,了解包裝對(duì)象的臨時(shí)性和手動(dòng)創(chuàng)建方式有助于編寫更高效和正確的代碼,感興趣的朋友跟隨小編一起看看吧
    2024-11-11
  • javascript 頁(yè)面跳轉(zhuǎn)方法集合

    javascript 頁(yè)面跳轉(zhuǎn)方法集合

    js 中實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的方法(window.location和window.open的區(qū)別)
    2009-03-03
  • layer設(shè)置maxWidth及maxHeight解決方案

    layer設(shè)置maxWidth及maxHeight解決方案

    這篇文章主要介紹了layer設(shè)置maxWidth及maxHeight解決方案,非常不錯(cuò),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2019-07-07
  • JavaSript中變量的作用域閉包的深入理解

    JavaSript中變量的作用域閉包的深入理解

    js中的變量都是公用的沒有靜態(tài)變量,下面為大家介紹下變量的作用域閉包,需要的朋友可以參考下
    2014-05-05

最新評(píng)論

社旗县| 喀喇沁旗| 罗田县| 晋宁县| 木里| 江达县| 新余市| 黄石市| 贡觉县| 泽库县| 康乐县| 潞西市| 岗巴县| 谢通门县| 榆树市| 大连市| 张家口市| 平陆县| 大厂| 永寿县| 团风县| 通辽市| 精河县| 镇雄县| 栾川县| 齐齐哈尔市| 三穗县| 灵宝市| 昆山市| 新闻| 江口县| 蓬溪县| 宿迁市| 紫云| 安阳县| 甘谷县| 富裕县| 陇川县| 徐水县| 罗山县| 扶绥县|