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)

      

  • 相关阅读:
    ubuntu安装后做得几件事情 【robby_chan】
    malloc函数的一种简单的原理性实现[转]
    了解B树 B+树
    win下格式转为utf8 编码 转码
    log4j2与slf4j日志桥接
    java获取当前行数
    java获取服务器ip地址解决linux上为127.0.0.1的问题
    log4j2的基本使用
    navicator使用之mysql
    log4j与log4j2日志文件的操作
  • 原文地址:https://www.cnblogs.com/RAINHAN/p/7095153.html
Copyright © 2011-2022 走看看