ドキュメント <br>nav {<br> height: 50px;<br>}<br> nav span {<br> margin: 0 5px;<br>}<br>.show {<br> color: red;<br>}<br> 手机: 锤子 T1 锤子 T2 坚果U1 锤子M1 坚果Pro 价格: 3200 2600 < ;a href="javascript:;">899 2799 2299 a> 屏幕: 399 600 800 1200 < /li><br>(function(){<br> var nav = document.querySelector('nav');<br> var li = document.querySelectorAll(' li');<br> var ids = [];<br> for(var i = 0; i </p> <li.length i></li.length> setClick(li[i],i);<br> }<br> function setClick(parent,index){<br> var option = parent.getElementsByTagName("a");<br> for(var i = 0; i <option .length i></option> /*<br> 建一数组<br> */<br> option[i].onclick = function(){<br> for(var i = 0; i <option.length i></option.length> option[i ].className = "";<br> }<br> this.className = "show";<br> var spam = ids[index];<br> if(ids[index]){<br> scan.children[0].innerHTML = this.innerHTML; <br> return;<br> }<br> span = document.createElement("span");<br> var a = document.createElement("a");<br> var Strong = document.createElement("strong");<br> a.innerHTML = "x ";<br> a.href="javascript:;";<br> a.onclick = function(){<br> nav.removeChild(span);<br> ids[index]="";<br> /*<br> 删除元素清空数组对象位<br> */<br> for(var i = 0; i < option.length; i++){<br/> option[i].className = "";<br/> }<br/> }<br/>strong.innerHTML = this.innerHTML;<br/>span.appendChild(strong );<br/>span.appendChild(a);<br/> ids[index] = span;<br/> /*<br/>元素生成之後,先存入量组的对应位<br/> */</p><p> /*<br/>按照数组の顺序再追加一遍元素<br/> */<br/> for(var i = 0;私は< ids.length; i++){<br/> if(ids[i]){<br/> nav.appendChild(ids[i]);<br/> }<br/> }<br/> };<br/> }<br/> }<br/>})(); <br/>