欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于JQuery實現(xiàn)相同內(nèi)容合并單元格的代碼

 更新時間:2011年01月12日 16:34:49   作者:  
我們就中和下利用JQuery來和他一個table里面相同內(nèi)容的單元格,這里代碼跟大家分享下,希望對大家有用
web前端開發(fā)的時候經(jīng)常會遇到要做表單的頁面或者做一些表格的效果如相同內(nèi)容要同一個單元格里面顯示,一般的方法是table里面在套table但是這種方法會增加頁面的負擔影響頁面加載速度但是如果用DIV有不好控制寫的css樣式要很多,那怎么辦呢?我們就中和下利用JQuery來和他一個table里面相同內(nèi)容的單元格,這里代碼跟大家分享下,希望對大家有用,如下:

頭部JQuery代碼
復(fù)制代碼 代碼如下:

<script type="text/javascript">
jQuery.fn.rowspan = function(colIdx) { //封裝的一個JQuery小插件
return this.each(function(){
var that;
$('tr', this).each(function(row) {
$('td:eq('+colIdx+')', this).filter(':visible').each(function(col) {
if (that!=null && $(this).html() == $(that).html()) {
rowspan = $(that).attr("rowSpan");
if (rowspan == undefined) {
$(that).attr("rowSpan",1);
rowspan = $(that).attr("rowSpan"); }
rowspan = Number(rowspan)+1;
$(that).attr("rowSpan",rowspan);
$(this).hide();
} else {
that = this;
}
});
});
});
}
$(function() {
$(“#table1″).rowspan(0);//傳入的參數(shù)是對應(yīng)的列數(shù)從0開始,哪一列有相同的內(nèi)容就輸入對應(yīng)的列數(shù)值
$(“#table1″).rowspan(2);
});
</script>

在body里面加入一個表格
復(fù)制代碼 代碼如下:

<body>
<table id="table1" border="1" cellpadding="5" cellspacing="0" width="300px">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>

<tr>
<td>1</td>
<td>f</td>
<td>3</td>
<td>s</td>
</tr>
</table>
</body>

IE效果  

火狐效果  

更多的前端開發(fā)可以關(guān)注 UI前端

相關(guān)文章

最新評論