1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| let plateKeyBorad = function(func){ let ele = document.createElement('div') ele.setAttribute('id',"plate-keyborad")
let arrArea = '京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使'; let arrLetter = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; let plateStr = [] let keyboradArea = document.createElement('div') keyboradArea.setAttribute('class',"keyborad-area") for(a of arrArea){ let e = document.createElement('div') let o = a e.innerHTML = o e.addEventListener('click',function(){ judgePlateLen(o) }) keyboradArea.appendChild(e) } for(a of "ABCDEF"){ let e = document.createElement('div') e.innerHTML = a e.setAttribute('class',"disabled") keyboradArea.appendChild(e) } let areaDel = document.createElement('div') areaDel.setAttribute('class',"del") areaDel.addEventListener('click',function(){ delPlate() }) keyboradArea.appendChild(areaDel)
let keyboradLetter = document.createElement('div') keyboradLetter.setAttribute('class',"keyborad-letter ") for(a of arrLetter){ let e = document.createElement('div') let o = a e.innerHTML = a if(["I","O"].includes(a)){ e.setAttribute('class',"disabled") }else{ e.addEventListener('click',function(){ judgePlateLen(o) }) } keyboradLetter.appendChild(e) } let letterDel = document.createElement('div') letterDel.setAttribute('class',"del") letterDel.addEventListener('click',function(){ delPlate() }) keyboradLetter.appendChild(letterDel)
ele.appendChild(keyboradArea) ele.appendChild(keyboradLetter) document.body.appendChild(ele)
function judgePlateLen(letter){ if(changeWait){ plateStr[changeNum] = letter if(func.callback){ func.callback({list:plateStr}) }else{ callback({type:plateStr}) } changeWait = false return false; } if(plateStr.length >= 8){ console.log('新能源车添加完成'); if(letter){ plateStr[plateStr.length-1] = letter } }else{ if(letter){ plateStr.push(letter) } } if(plateStr.length == 7){ console.log('燃油车添加完成'); } if(plateStr.length <= 0){ keyboradLetter.style.display = "none" keyboradArea.style.display = "flex" } if(plateStr.length >= 1){ keyboradArea.style.display = "none" keyboradLetter.style.display = "flex" } if(func.callback){ func.callback({list:plateStr}) }else{ callback({type:plateStr}) } } function delPlate(){ plateStr.pop() judgePlateLen() } function callback(obj){ console.log(obj.plateStr); } let changeWait = false let changeNum = -1 function change(num){ changeNum = num changeWait = true if(num <= 0){ keyboradLetter.style.display = "none" keyboradArea.style.display = "flex" }else{ keyboradArea.style.display = "none" keyboradLetter.style.display = "flex" } } return { change } }
|