Code
Dmplatform. Tools. tabletools = (function (){
/** Internal Method */
// Dynamic Cursor line
(Function hightlightrow (){
// The following figure shows the Dynamic Cursor row and the selected result.
$ (". Resulttable tbody TR"). Live ("Mouseover", function (){
$ (This). addclass ("tips_row_hover ");
}). Live ("mouseout", function (){
$ (This). removeclass ("tips_row_hover ");
});
})();
(Function checkboxcheck (){
$ (". Resulttable tbody TD"). Live ("click", function (event) {// This method is used to change the color of the row and whether all rows are selected
VaR selectall = $ (this). Parents ("table"). Find ("thead: checkbox: eq (0 )");
If(event.tar get! = This ){
If ($ (this). Parents ("TR"). Find (": checkbox. selector"). ATTR ("checked ")){
$ (This). Parents ("TR"). addclass ("tips_row_selected"); // lele.info ("coloring ");
If ($ (this). Parents ("tbody"). Find (": checkbox: Not ([checked]). selector"). Length = 0 ){
Selectall. ATTR ("checked", "checked ");
}
} Else {
$ (This). Parents ("TR"). removeclass ("tips_row_selected"); // lele.info ("Fade ");
Selectall. removeattr ("checked ");
}
}
});
})();
// Select all checkboxes in the header
(Function checkall (){
$ (". Selectall"). Live ("click", function (){
VaR rstable = $ (this). Parents ("table ");
If ($ (this). ATTR ("checked ")){
Rstable. Find ("tbody: checkbox: Not (: checked). selector"). ATTR ("checked", "checked ");
Rstable. Find ("tbody: checkbox"). Parents ("TR"). addclass ("tips_row_selected ");
} Else {
Rstable. Find ("tbody: checkbox: checked. selector"). removeattr ("checked ");
Rstable. Find ("tbody TR"). removeclass ("tips_row_selected ");
}
});
})();
// Serialize all input types of the input object
Function serialize (OBJ ){
If (OBJ = undefined ){
Throw new error ("dmplatform. Tools. tabletools: OBJ of serialize is undefined! ");
}
If (typeof (OBJ )! = "Object "){
Throw new error ("dmplatform. Tools. tabletools: OBJ of serialize typeof isn't object, is" + typeof (OBJ ));
}
VaR inputs = $ (OBJ). Find (": input, select, textarea ");
VaR inputarray = new array ();
VaR tempjson;
Inputs. Each (function (){
If ($ (this). ATTR ("name ")! = Undefined ){
Tempjson = new object ();
// If there is a server-side control
If ($ (this). ATTR ("class") = "runat_server "){
Tempjson. Name = $ (this). ATTR ("name"). Match (/\ W + $/) [0];
} Else {
Tempjson. Name = $ (this). ATTR ("name ");
}
Tempjson. value = $ (this). Val ();
Inputarray [inputarray. Length] = tempjson;
}
});
Return inputarray;
}
Return {
Getserializeonlyjson: function (OBJ ){
Return JSON. stringify (serialize (OBJ ));
},
Getserialize: function (OBJ ){
Return serialize (OBJ );
}
}
})();
The following is a simplified and abstract demo similar to the above Code.
Code
<body>
<script>
TestObj=(function(){
(function A(){alert('A');})();
(function B(){alert('B');})();
return {C:function(){alert('haha')},
D:function(){alert('hehe')}
};
})()
TestObj.C();
TestObj.D();
</script>
</body>