Recently, when working on a project, the customer requested that the data in the table could be dragged and selected, so he wrote the following method using JS. Supports IE, FIREFOX, and other browsers. You can select, select, reverse, and clear all rows and columns of data, and select all cells in the rectangle range dragged from the data table.
PS:
1. If no data exists in the data cell, set the ID to null or remove the ID. The style is "inactive". This cell will be skipped when you select.
2. If you do not want to select a cell, set the class to "bg_green", and skip this cell when you select it.
<P> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> <ptml> <pead> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "> <title> calendar </title> </P> <style type =" text/css ">/* button style */. button {padding: 2px; color: # F5F5F5; background-color: #3665A5; border-width: 1px 2px 2px 1px; border-color: # D2D2D2 #305B93 #305B93 # D2D2D2; border-style: solid; font: bold 14px verdana;} </P> <P> body, td {margin: 0; font: 12px verdana; cursor: default ;} # ca td {/* width: 20px; height: 25px; */border-right: 1px solid; border-bottom: 1px solid; text-align: center ;}. daysTitle td {border-right: 1px solid # A6D2FF; text-align: center; font-weight: bold ;}. font_red {color: red ;}. monthsTitle td {border-bottom: 1px solid # A6D2FF; text-align: center; color: # fafafa ;}. bg_red {background-color: # FF0000; color: # FFFFCC; border-color: # FFCCCC ;}. bg_green {background-color: #00CC00 ;}. inactive {background-color: # E1F0FF; border-color: # A6D2FF ;}. noData {background-color: # ccc; border-color: #999 ;} </style> </pead> </P> <body> <table width = "100%" border = "0" cellspacing = "0" cellpadding = "0"> <tr align = "center" valign = "middle" bgcolor = "#99 CCFF"> <td height = "40" colspan = "2"> <INPUT class = button type = submit value = "<" name = Submit3> 2006 <INPUT class = button type = submit value = ">" name = Submit4> </td> </P> <P> </tr> <tr bgcolor = "# 0099CC"> <td height = "25"> </td> <td height = "25" align = "left" valign =" top "> <table width =" 100% "border =" 0 "cellpadding =" 0 "cellspacing =" 0 "class =" daysTitle "id =" days "> </P> <P> <tr align = "center" valign = "middle"> <td width = "20" height = "25"> M </td> <td width = "20 "height =" 25 "> T </td> <td width =" 20 "height =" 25 "> W </td> </P> <td width = "20" height = "25"> T </td> <td width = "20" height = "25"> F </td> <td width = "20" height = "25" class = "font_red"> S </td> <td width = "20" height = "25" class = "font_red"> S </td> </P> <td width = "20" height = "25"> M </td> <td width = "20" height = "25"> T </ td> <td width = "20" height = "25"> W </td> <td width = "20" height = "25"> T </td> </ p> <td width = "20" height = "25"> F </td> <td width = "20" height = "25" class = "font_red"> S </td> <td width = "20" height = "25" class = "font_red"> S </td> <td width = "20" height = "25 "> M </td> </P> <td width =" 20 "height =" 25 "> T </td> <td width =" 20 "height = "25"> W </td> <td width = "20" height = "25"> T </td> <td width = "20" height = "25"> F </td> </P> <td width = "20" height = "25" class = "font_red"> S </td> <td width = "20" height = "25" class = "font_red"> S </td> <td width = "20" height = "25"> M </td> <td width = "20" height = "25"> T </td> </P> <td width = "20" height = "25"> W </td> <td width = "20" height = "25"> T </td> <td width = "20" height = "25"> F </td> <td width = ""20" height = "25" class = "font_red"> S </td> </P> <td width = "20" height = "25" class = "font_red"> S </td> <td width = "20" height = "25"> M </td> <td width = "20" height = "25"> T </td> <td width = "20" height = "25"> W </td> </P> <td width = "20" height =" 25 "> T </td> <td width =" 20 "height =" 25 "> F </td> <td width =" 20 "height =" 25 "class = "font_red"> S </td> <td width = "20" height = "25" class = "font_red"> S </td> </P> <td width = "20" height = "25"> M </td> <td width = "20" height = "25"> T </td> <td width =" 20 "height =" 25 "> W </td> <td width =" 20 "height =" 25 "> T </td> </P> <td width = "20" height = "25"> F </td> <td width = "20" height = "25" class = "font_red"> S </td> <td width = "20" height = "25" class = "font_red"> S </td> </tr> </P> </table> </td> </tr> <td width = "60" align = "left" valign = "top" bgcolor = "# 0099CC"> <table width = "100%" border = "0" cellpadding = "0" cellspacing = "0" id = "months" class = "monthsTitle"> </P> <tr> <td height =" 25 "align =" center "valign =" middle "> Jan </td> </tr> <td height =" 25 "align =" center "valign =" middle "> Feb </td> </P> </tr> <td height =" 25 "align =" center "valign =" middle "> mar </td> </tr> </P> <td height = "25" align = "center" valign = "middle"> Apr </ td> </tr> <td height = "25" align = "center" valign = "middle"> May </td> </tr> </P> <P> <tr> <td height = "25" align = "center" valign = "middle"> Jun </td> </tr> <td height = "25" align = "center" valign = "middle"> Jul </td> </P> </tr> <td height = "25" align = "center" valign = "middle"> Aug </td> </tr> </P> <td height = "25" align =" center "valign =" middle "> Sep </td> </tr> <td height =" 25 "align =" center "valign =" middle "> Oct </td> </tr> </P> <tr> <td height = "25" align = "center" valign = "middle"> Nov </td> </tr> <td height = "25" align = "center" valign = "middle"> Dec </td> </P> </tr> </table> </P> </td> <td align = "left" valign = "top"> </td> </P> <P> </tr> </table> <table width = "100%" height = "40" border = "0" cellpadding = "0" cellspacing = "0" bgcolor = "# 0099CC "> <tr> <td> </P> <td width =" 500 "> <input name =" Submit "type =" button "class =" button "onClick =" selectAll (true) "value =" Select All "> <input name =" Submit "type =" button "class =" button "onClick =" resetAll () "value =" Reset All "> <input name =" Submit "type =" button "class =" button "onClick =" selectAll (false) "value =" Reverse Select "> </td> </tr> </table> </P> </body> </ptml> </P>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]