原生js寫的一個下拉框功能插件

用原生js寫的一個下拉框功能插件
/**
*下單框原生js插件
* dropdown作爲元素class屬性的屬性值作用在需要添加下拉框效果的元素上
*example:
	
<script src="dropdown.js"></script> **/ var dropdowns = document.getElementsByClassName("dropdown"); Array.prototype.slice.call(dropdowns,0).forEach(function(item,index){ var dropdown = item; var lis = Array.prototype.slice.call(dropdown.children,0); lis.forEach(function(item,index){ item.setAttribute("style","display:none"); }) dropdown.firstElementChild.removeAttribute("style"); dropdown.onclick = function(){ lis.forEach(function(item,index){ var value = item.style.display; if(value=="none"){ item.setAttribute("style","display:visibility"); }else{ item.setAttribute("style","display:none"); dropdown.firstElementChild.removeAttribute("style"); } }) } });
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章