• 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)

      

  • 相关阅读:
    安装黑苹果的config.plist
    navicat for mysql 导出数据的坑
    js中的深层复制
    js写的一个HashMap
    js前台数据校验
    nginx对上传文件大小的限制
    tomcat用户配置,内存配置,pid配置
    redis安装及使用
    程序端口被占用分析
    zookeeper+dubbo-admin开发dubbo应用
  • 原文地址:https://www.cnblogs.com/RAINHAN/p/7095153.html
Copyright © 2020-2023  润新知