Created
March 13, 2017 09:39
-
-
Save TooBug/4eaf8d542a0075214d7974efa673c7d8 to your computer and use it in GitHub Desktop.
表格适配移动端代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.md-preview table').each(function(){ | |
var $table = $(this); | |
var $th = $table.find('thead th'); | |
var colCount = $th.length; | |
var transformCols = $th.slice(1).map(function(index){ | |
var content = this.innerHTML; | |
if(index > 0){ | |
$(this).remove(); | |
} | |
return content; | |
}).get(); | |
$th.eq(1).html('项目').attr('colspan', '2'); | |
var $originalTr = $table.find('tbody tr'); | |
$originalTr.each(function(index){ | |
var $thisTr = $(this); | |
var values = $thisTr.find('td:gt(0)').map(function(index){ | |
var content = this.innerHTML; | |
if(index > 1){ | |
$(this).remove(); | |
} | |
return content; | |
}).get(); | |
for(var i=transformCols.length; i>1; i--){ | |
$thisTr.after('<tr><td>' + | |
transformCols[i-1] + | |
'</td><td>' + | |
values[i-1] + | |
'</td></tr>'); | |
} | |
$thisTr.find('td:eq(0)').attr('rowspan', transformCols.length); | |
$thisTr.find('td:eq(1)').css('text-align', 'left').html(transformCols[0]); | |
$thisTr.find('td:eq(2)').css('text-align', 'left').html(values[0]); | |
/*for(var i=0; i<transformCols.length; i++){ | |
}*/ | |
}); | |
console.log(transformCols); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment