During front-end web development, you will often encounter pages to form or make some tables. For example, if the same content is to be displayed in the same cell, the general method is to set the table in the table, but this method will increase the page load speed and affect the page loading speed. But if there is a lot of css styles that cannot be controlled by DIV, what should we do? Let's just use JQuery to share the cells with the same content in a table. The code here will be useful to you as follows:
Header JQuery code
Copy codeThe Code is as follows:
<Script type = "text/javascript">
JQuery. fn. rowspan = function (codecomx) {// a small JQuery plug-in encapsulated
Return this. each (function (){
Var that;
$ ('Tr', this). each (function (row ){
$ ('Td: eq ('+ codecomx +') ', this). filter (': visible '). each (function (col ){
If (that! = Null & lt; this).html () = Hangzhou (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); // The input parameter indicates that the number of columns starts from 0. If any column has the same content, enter the corresponding column value.
$ ("# Table1"). rowspan (2 );
});
</Script>
Add a table to the body.
Copy codeThe Code is as follows:
<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 Effect
Firefox Effect
More front-end development can focus on the UI front-end