渲染的问题 关于优化

https://img4.mukewang.com/5c7f31690001dbdc08000693.jpg

需求:根据页面的每个UL的里面的input的value值然后渲染出对应li的选中的状态,【不依赖第三方库,原生实现】
现在功能已经实现了,但是在性能这边是相当不好的 , 请大神给他个思路或者一段代码 让我理解一下 谢谢

米琪卡哇伊
浏览 513回答 2
2回答

互换的青春

<div id="list">&nbsp; &nbsp; <ul>&nbsp; &nbsp; &nbsp; &nbsp; <input type="hidden" value="2" />&nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; </ul>&nbsp; &nbsp; <ul>&nbsp; &nbsp; &nbsp; &nbsp; <input type="hidden" value="1" />&nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; </ul>&nbsp; &nbsp; <ul>&nbsp; &nbsp; &nbsp; &nbsp; <input type="hidden" value="3" />&nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; </ul></div>init();function init() {&nbsp; &nbsp; var dul = document.getElementById('list'), uls = dul.children, i = 0, len = uls.length;&nbsp; &nbsp; for (; i < len;) {&nbsp; &nbsp; &nbsp; &nbsp; var lis = uls[i++].children, index = lis[0].value;&nbsp; &nbsp; &nbsp; &nbsp; lis[index].className = index;&nbsp; &nbsp; &nbsp; &nbsp; //lis[index].innerHTML = index;&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript