zoukankan      html  css  js  c++  java
  • js 将表格的数组存储为二维数组

    表格数据:

    <table id="tb" width="100%" border="1" cellspacing="3" cellpadding="3" style="text-align: center; display: none;">
    		    <caption style="margin-bottom: 15px">商家端功能权限列表</caption>
    		        <tr>
    		        	<!--角色-->
    		        	<th style=" 30px !important;">功能模块显示</th>
    		            <th>seller-M</th>        
    		            <th>seller-E</th>
    		            <th>zone-P</th>
    		            <th>city-P</th>
    		            <th>seller-H-R</th>
    		            <th>advertiser</th>
    		        </tr>
    		        <!--功能-->
    		        <tr>
    		        	<th>昨日销售</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>1</td>            
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		        <tr>
    		        	<th>商家余额</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		        <tr>
    		        	<th>待配送</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>    
    		        <tr>
    		        	<th>营业状态</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		        <tr>
    		        	<th>配送中</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		        <tr>
    		        	<th>商城销售</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		        <tr>
    		        	<th>收支流水</th>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>1</td>
    		        </tr>
    		        <tr>
    		        	<th>分类管理</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		        <tr>
    		        	<th>商品管理</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		        <tr>
    		        	<th>发红包</th>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>1</td>
    		        </tr>
    		        <tr>
    		        	<th>优惠券</th>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		         <tr>
    		        	<th>数据报表</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		         <tr>
    		        	<th>我的店铺</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		        </tr>
    		         <tr>
    		        	<th>意见反馈</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>1</td>
    		        </tr>
    		        <tr>
    		        	<th>联系我们</th>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>1</td>
    		            <td>0</td>
    		            <td>1</td>
    		        </tr>
    		        <tr>
    		        	<th>房屋验证</th>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>0</td>
    		            <td>1</td>
    		            <td>0</td>
    		        </tr>
       		 </table>
    

      js关键代码

    // 	权限列表生成二维数组
    		var tr = document.getElementsByTagName('tr');
    		var td = document.getElementsByTagName('td');
    		var arr2 = new Array();
    		//	初始化二维数组
    		for(var i = 0; i < tr.length-1;i++){
    			arr2[i] = new Array();
    			for(var j = 0; j < td.length/(tr.length-1); j++){
    				arr2[i][j] = '';
    			}
    		}
    		
    //		console.log(arr2.length);
    		//	生成权限列表二维数组
    		for (var x = 0; x < tr.length-1; x++) {                            
    		    for (var y = 0; y < td.length/(tr.length-1); y++) {            
    		        arr2[x][y] = td[x*(td.length/(tr.length-1))+y].innerText;
    		        console.log('arr2['+x+']['+y+'] ==  '+ arr2[x][y] )
    		    }    
    		}
              alert (arr2)

      

  • 相关阅读:
    win10系统下office 2019激活
    如何根据【抖音分享链接】去掉抖音水印
    Java多线程学习之ThreadLocal源码分析
    Java多线程学习之synchronized总结
    Java多线程学习之线程的取消与中断机制
    Java多线程学习之Lock与ReentranLock详解
    Java多线程学习之线程池源码详解
    MyBatis 一、二级缓存和自定义缓存
    Spring 高级依赖注入方式
    Spring 依赖注入的方式
  • 原文地址:https://www.cnblogs.com/RAINHAN/p/7095153.html
Copyright © 2011-2022 走看看