zoukankan      html  css  js  c++  java
  • getByClassName2016/4/21

    <!DOCTYPE HTML>
    <html>
    	<head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    	<title>ll无标题文档</title>
    	<script>
    window.onload=function(){
         
    	 var ali=getElementByClassName(document,'li','box');
    	 for(var i=0;i<ali.length;i++)
    	 {
    		ali[i].style.background='red';
    	 }
    	alert(ali.length);
    	 function getElementByClassName(parent,tagName,className){
    			 var aEls=parent.getElementsByTagName(tagName);
    			 var arr=[]; 
    			 for(var i=0;i<aEls.length;i++)
    			 {
    				var aclassName=aEls[i].className.split(' ');
    					for(var j=0;j<aclassName.length;j++)
    					{
    						if(aclassName[j]==className){
    						arr.push(aEls[i]);
    						break;
    							}
    				
    					}
    			 
    	 
    			 
    			}
    			 return arr;
    
    
    	}
    };
     
    </script>
    	
    	
    	
    	</head>
    
    <body>
    	<ul id="ul1">
    		<li>111111</li>
    		<li>22222</li>
    		<li class="box ">33333</li>
    		<li class="box ">444444</li>
    	</ul>
    	   
    </body>
    </html>
    

      

  • 相关阅读:
    css3线性渐变
    php的%s
    面向对象
    excel导入导出
    保存Excel
    保存word
    图片预览
    验证日期输入格式
    级联菜单
    中级前端知识点提要
  • 原文地址:https://www.cnblogs.com/hduhdc/p/5417317.html
Copyright © 2011-2022 走看看