jquery Simple operation
A: Introduction
In front of the side has been very small white, only to understand some basic JS, is not too familiar with, jquery is also, use sometimes very simple usage also to check, the system of learning, the commonly used records to do a memo, but also notes. Constantly updated ...
Two: Common functions
1, $ (' #id '). Remove ()--Removes the element with ID ID.
2, $ (' #id '). Empty ()--Removes the contents of an element with ID ID.
Three: Utility Plug-in
1. Cells that merge the same content in the table:
A) content:
Encapsulates a jquery widget that implements the same content merged cell code jQuery.fn.rowspan = function (colidx) {return This.each (function () {var that;$ (' tr '), This). each (the function (row) {$ (' td:eq (' + colidx + ') ', this). The filter (': Visible '). each (the function (col) {if (That! = null&& Amp $ (this). the 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;});});});
b) test content: Dynamically generated data table, page and JS:
<body onload= "init ();" ><div align= "center" ><table id= "logdetailtable" width= "99%" border= "1" collapse= "collapse" ><thead ><tr><th width= "20%" height= "40px" > Project name </th><th width= "20%" height= "40px" > Monitoring type </th ><th width= "35%" height= "40px" > Sub-project name </th><th width= "25%" height= "40px" > Log information </th></tr ></thead><tbody id= "Logdetailinfo" ></TBODY></TABLE></DIV></BODY>
function init () {//Get DataSet result...//build Table:for (var i in result) {fillshowlogtable (result[i]);} Specifies the rows (' #logDetailTable ') of the table to be merged. rowspan (0); $ (' #logDetailTable '). rowspan (1);} function fillshowlogtable (list) {var str = '; str + = ' <tr><td style= ' width:20%;text-align:center ' > ' +list. Pro_title+ ' </td> '; str + = ' <td style= "Width:20%;height:30px;text-align:center" > "+list. sub_project_name+ ' </td> '; str + = ' <td style= "Width:35%;height:30px;text-align:center" > "+list. task_name+ ' </td> '; if (list. Tip_value = = ' no ') {list. Tip_value = ' no new log '; str + = ' <td class= "Nonewlog" style= "Width:25%;height:30px;text-align:center" > ' +list. Tip_value+ ' </td></tr> ';} else if (list. Tip_value = = ' yes ') {list. Tip_value = ' new log '; str + = ' <td class= "Hasnewlog" style= "Width:25%;height:30px;text-align:center" > ' +list. Tip_value+ ' </td></tr> ';} $ (str). AppendTo ($ (' #logDetailInfo '));}
c) Test results:
Summarize:
Apply. Practice is the quickest shortcut!
jquery Simple operation