有没有办法(我不知道用合适的词来形容它)来扭转jQuery的局面?用一个函数还是什么?
例如,我有一个这样的表:
<table>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
我希望是这样的:
<table>
<tr>
<th></th>
<td></td>
</tr>
<tr>
<th></th>
<td></td>
</tr>
<tr>
<th></th>
<td></td>
</tr>
</table>
发布于 2014-07-23 21:54:17
试试这段代码
<style>
td { padding:5px; border:1px solid #ccc;}
</style>
<script>
$("a").click(function(){
$("table").each(function() {
var $this = $(this);
var newrows = [];
$this.find("tr").each(function(){
var i = 0;
$(this).find("td").each(function(){
i++;
if(newrows[i] === undefined) { newrows[i] = $("<tr></tr>"); }
newrows[i].append($(this));
});
});
$this.find("tr").remove();
$.each(newrows, function(){
$this.append(this);
});
});
return false;
});
</script>
<table>
<tr>
<td>Heading1</td>
<td>Heading2</td>
<td>Heading3</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
</table>
<p><a href="#">Do it.</a></p>
不要忘了链接必要的(jquery1.6)文件和适当的标签。
尝试提供链接http://jsfiddle.net/CsgK9/2/
有关原始视图https://stackoverflow.com/a/6298066,请参阅此链接
https://stackoverflow.com/questions/24911998
复制相似问题