收藏列表
标题 | 标签 | 来源 | |
javascript 给td赋值,innerText | http://heisetoufa.iteye.com/blog/645195 | ||
1.<script language="javascript"> 2.ttd.innerText = "td的值"; 3.</script> 4. 5.<td id="ttd"></td> |
|||
javascript 获取select标签内容,汉字,中间 | http://heisetoufa.iteye.com/blog/654111 | ||
1.document.getElementById("selid").options[window.document.getElementById("selid").selectedIndex].text |
|||
javascript 日期控件,IE6中被select标签盖住的BUG,用iframe修正 | http://heisetoufa.iteye.com/blog/675466 | ||
1.<HTML> 2.<HEAD> 3.<TITLE></TITLE> 4.<script language="javascript"> 5.function PopupCalendar(InstanceName) 6.{ 7. ///Global Tag 8. this.instanceName=InstanceName; 9. ///Properties 10. this.separator="-" 11. this.oBtnTodayTitle="Today" 12. this.oBtnCancelTitle="Cancel" 13. this.weekDaySting=new Array("S","M","T","W","T","F","S"); 14. this.monthSting=new Array("January","February","March","April","May","June","July","August","September","October","November","December"); 15. this.Width=200; 16. this.currDate=new Date(); 17. this.today=new Date(); 18. this.startYear=1970; 19. this.endYear=2010; 20. ///Css 21. this.divBorderCss="1px solid #BCD0DE"; 22. this.tableBorderColor="#CCCCCC" 23. ///Method 24. this.Init=CalendarInit; 25. this.Fill=CalendarFill; 26. this.Refresh=CalendarRefresh; 27. this.Restore=CalendarRestore; 28. ///HTMLObject 29. this.oTaget=null; 30. this.oPreviousCell=null; 31. this.sDIVID=InstanceName+"oDiv"; 32. this.sFrameID = InstanceName+"oFrame"; 33. this.sTABLEID=InstanceName+"oTable"; 34. this.sMONTHID=InstanceName+"oMonth"; 35. this.sYEARID=InstanceName+"oYear"; 36. 37.} 38.function CalendarInit() ///Create panel 39.{ 40. var sMonth,sYear 41. sMonth=this.currDate.getMonth(); 42. sYear=this.currDate.getYear(); 43. htmlAll="<iframe id='"+this.sFrameID+"' frameborder=0 style='position: absolute;z-index: 9998;display: none'></iframe><div id='"+this.sDIVID+"' style='display:none;position:absolute;width:"+this.Width+";border:"+this.divBorderCss+";padding:2px;background-color:#FFFFFF;z-index: 9999'>"; 44. htmlAll+="<div align='center'>"; 45. /// Month 46. htmloMonth="<select id='"+this.sMONTHID+"' onchange=CalendarMonthChange("+this.instanceName+") style='width:50%'>"; 47. for(i=0;i<12;i++) 48. { 49. htmloMonth+="<option value='"+i+"'>"+this.monthSting[i]+"</option>"; 50. } 51. htmloMonth+="</select>"; 52. /// Year 53. htmloYear="<select id='"+this.sYEARID+"' onchange=CalendarYearChange("+this.instanceName+") style='width:50%'>"; 54. for(i=this.startYear;i<=this.endYear;i++) 55. { 56. htmloYear+="<option value='"+i+"'>"+i+"</option>"; 57. } 58. htmloYear+="</select></div>"; 59. /// Day 60. htmloDayTable="<table id='"+this.sTABLEID+"' width='100%' border=0 cellpadding=0 cellspacing=1 bgcolor='"+this.tableBorderColor+"'>"; 61. htmloDayTable+="<tbody bgcolor='#ffffff'style='font-size:13px'>"; 62. for(i=0;i<=6;i++) 63. { 64. if(i==0) 65. htmloDayTable+="<tr bgcolor='#98B8CD'>"; 66. else 67. htmloDayTable+="<tr>"; 68. for(j=0;j<7;j++) 69. { 70. if(i==0) 71. { 72. htmloDayTable+="<td height='20' align='center' valign='middle' style='cursor:hand'>"; 73. htmloDayTable+=this.weekDaySting[j]+"</td>" 74. } 75. else 76. { 77. htmloDayTable+="<td height='20' align='center' valign='middle' style='cursor:hand'"; 78. htmloDayTable+=" onmouseover=CalendarCellsMsOver("+this.instanceName+")"; 79. htmloDayTable+=" onmouseout=CalendarCellsMsOut("+this.instanceName+")"; 80. htmloDayTable+=" onclick=CalendarCellsClick(this,"+this.instanceName+")>"; 81. htmloDayTable+=" </td>" 82. } 83. } 84. htmloDayTable+="</tr>"; 85. } 86. htmloDayTable+="</tbody></table>"; 87. /// Today Button 88. htmloButton="<div align='center' style='padding:3px'>" 89. htmloButton+="<button style='width:40%;border:1px solid #BCD0DE;background-color:#eeeeee;cursor:hand'" 90. htmloButton+=" onclick=CalendarTodayClick("+this.instanceName+")>"+this.oBtnTodayTitle+"</button> " 91. htmloButton+="<button style='width:40%;border:1px solid #BCD0DE;background-color:#eeeeee;cursor:hand'" 92. htmloButton+=" onclick=CalendarCancel("+this.instanceName+")>"+this.oBtnCancelTitle+"</button> " 93. htmloButton+="</div>" 94. /// All 95. htmlAll=htmlAll+htmloMonth+htmloYear+htmloDayTable+htmloButton+"</div>"; 96. document.write(htmlAll); 97. this.Fill(); 98.} 99.function CalendarFill() /// 100.{ 101. var sMonth,sYear,sWeekDay,sToday,oTable,currRow,MaxDay,sDaySn,sIndex,rowIndex,cellIndex,oSelectMonth,oSelectYear 102. sMonth=this.currDate.getMonth(); 103. sYear=this.currDate.getYear(); 104. sWeekDay=(new Date(sYear,sMonth,1)).getDay(); 105. sToday=this.currDate.getDate(); 106. oTable=document.all[this.sTABLEID]; 107. currRow=oTable.rows[1]; 108. MaxDay=CalendarGetMaxDay(sYear,sMonth); 109. 110. oSelectMonth=document.all[this.sMONTHID] 111. oSelectMonth.selectedIndex=sMonth; 112. oSelectYear=document.all[this.sYEARID] 113. for(i=0;i<oSelectYear.length;i++) 114. { 115. if(parseInt(oSelectYear.options[i].value)==sYear)oSelectYear.selectedIndex=i; 116. } 117. //// 118. for(sDaySn=1,sIndex=sWeekDay;sIndex<=6;sDaySn++,sIndex++) 119. { 120. if(sDaySn==sToday) 121. { 122. currRow.cells[sIndex].innerHTML="<font color=red><i><b>"+sDaySn+"</b></i></font>"; 123. this.oPreviousCell=currRow.cells[sIndex]; 124. } 125. else 126. { 127. currRow.cells[sIndex].innerHTML=sDaySn; 128. currRow.cells[sIndex].style.color="#666666"; 129. } 130. CalendarCellSetCss(0,currRow.cells[sIndex]); 131. } 132. for(rowIndex=2;rowIndex<=6;rowIndex++) 133. { 134. if(sDaySn>MaxDay)break; 135. currRow=oTable.rows[rowIndex]; 136. for(cellIndex=0;cellIndex<currRow.cells.length;cellIndex++) 137. { 138. if(sDaySn==sToday) 139. { 140. currRow.cells[cellIndex].innerHTML="<font color=red><i><b>"+sDaySn+"</b></i></font>"; 141. this.oPreviousCell=currRow.cells[cellIndex]; 142. } 143. else 144. { 145. currRow.cells[cellIndex].innerHTML=sDaySn; 146. currRow.cells[cellIndex].style.color="#666666"; 147. } 148. CalendarCellSetCss(0,currRow.cells[cellIndex]); 149. sDaySn++; 150. if(sDaySn>MaxDay)break; 151. } 152. } 153.} 154.function CalendarRestore() /// Clear Data 155.{ 156. var oTable 157. oTable=document.all[this.sTABLEID] 158. for(i=1;i<oTable.rows.length;i++) 159. { 160. for(j=0;j<oTable.rows[i].cells.length;j++) 161. { 162. CalendarCellSetCss(0,oTable.rows[i].cells[j]); 163. oTable.rows[i].cells[j].innerHTML=" "; 164. } 165. } 166.} 167.function CalendarRefresh(newDate) /// 168.{ 169. this.currDate=newDate; 170. this.Restore(); 171. this.Fill(); 172.} 173.function CalendarCellsMsOver(oInstance) /// Cell MouseOver 174.{ 175. var myCell 176. myCell=event.srcElement; 177. CalendarCellSetCss(0,oInstance.oPreviousCell); 178. if(myCell) 179. { 180. CalendarCellSetCss(1,myCell); 181. oInstance.oPreviousCell=myCell; 182. } 183.} 184.function CalendarCellsMsOut(oInstance) ////// Cell MouseOut 185.{ 186. var myCell 187. myCell=event.srcElement; 188. CalendarCellSetCss(0,myCell); 189.} 190.function CalendarCellsClick(oCell,oInstance) 191.{ 192. var sDay,sMonth,sYear,newDate 193. sYear=oInstance.currDate.getFullYear(); 194. sMonth=oInstance.currDate.getMonth(); 195. sDay=oInstance.currDate.getDate(); 196. if(oCell.innerText!=" ") 197. { 198. sDay=parseInt(oCell.innerText); 199. if(sDay!=oInstance.currDate.getDate()) 200. { 201. newDate=new Date(sYear,sMonth,sDay); 202. oInstance.Refresh(newDate); 203. } 204. } 205. sDateString=sYear+oInstance.separator+CalendarDblNum(sMonth+1)+oInstance.separator+CalendarDblNum(sDay); ///return sDateString 206. if(oInstance.oTaget.tagName=="INPUT") 207. { 208. oInstance.oTaget.value=sDateString; 209. } 210. document.getElementById(oInstance.sFrameID).style.display = document.all[oInstance.sDIVID].style.display="none"; 211.} 212.function CalendarYearChange(oInstance) /// Year Change 213.{ 214. var sDay,sMonth,sYear,newDate 215. sDay=oInstance.currDate.getDate(); 216. sMonth=oInstance.currDate.getMonth(); 217. sYear=document.all[oInstance.sYEARID].value 218. newDate=new Date(sYear,sMonth,sDay); 219. oInstance.Refresh(newDate); 220.} 221.function CalendarMonthChange(oInstance) /// Month Change 222.{ 223. var sDay,sMonth,sYear,newDate 224. sDay=oInstance.currDate.getDate(); 225. sMonth=document.all[oInstance.sMONTHID].value 226. sYear=oInstance.currDate.getYear(); 227. newDate=new Date(sYear,sMonth,sDay); 228. oInstance.Refresh(newDate); 229.} 230.function CalendarTodayClick(oInstance) /// "Today" button Change 231.{ 232. oInstance.Refresh(new Date()); 233.} 234.function getDateString(oInputSrc,oInstance) 235.{ 236. if(oInputSrc&&oInstance) 237. { 238. CalendarDiv=document.all[oInstance.sDIVID]; 239. var frame = document.getElementById(oInstance.sFrameID); 240. 241. oInstance.oTaget=oInputSrc; 242. CalendarDiv.style.left=CalendargetPos(oInputSrc,"Left") + "px"; 243. CalendarDiv.style.top=CalendargetPos(oInputSrc,"Top")+oInputSrc.offsetHeight + "px"; 244.//CalendarDiv.style.display=(CalendarDiv.style.display=="none")?"":"none"; 245. frame.style.display = CalendarDiv.style.display=(CalendarDiv.style.display=="none")?"":"none"; 246. with (frame.style) { 247. left = CalendarDiv.offsetLeft - 1 + "px"; 248. top = CalendarDiv.offsetTop - 1 + "px"; 249. height = CalendarDiv.offsetHeight; 250. width = CalendarDiv.offsetWidth; 251. } 252. 253. } 254.} 255.function CalendarCellSetCss(sMode,oCell) /// Set Cell Css 256.{ 257. // sMode 258. // 0: OnMouserOut 1: OnMouseOver 259. if(sMode) 260. { 261. oCell.style.border="1px solid #5589AA"; 262. oCell.style.backgroundColor="#BCD0DE"; 263. } 264. else 265. { 266. oCell.style.border="1px solid #FFFFFF"; 267. oCell.style.backgroundColor="#FFFFFF"; 268. } 269.} 270.function CalendarGetMaxDay(nowYear,nowMonth) /// Get MaxDay of current month 271.{ 272. var nextMonth,nextYear,currDate,nextDate,theMaxDay 273. nextMonth=nowMonth+1; 274. if(nextMonth>11) 275. { 276. nextYear=nowYear+1; 277. nextMonth=0; 278. } 279. else 280. { 281. nextYear=nowYear; 282. } 283. currDate=new Date(nowYear,nowMonth,1); 284. nextDate=new Date(nextYear,nextMonth,1); 285. theMaxDay=(nextDate-currDate)/(24*60*60*1000); 286. return theMaxDay; 287.} 288.function CalendargetPos(el,ePro) /// Get Absolute Position 289.{ 290. var ePos=0; 291. while(el!=null) 292. { 293. ePos+=el["offset"+ePro]; 294. el=el.offsetParent; 295. } 296. return ePos; 297.} 298.function CalendarDblNum(num) 299.{ 300. if(num<10) 301. return "0"+num; 302. else 303. return num; 304.} 305.function CalendarCancel(oInstance) ///Cancel 306.{ 307. CalendarDiv=document.all[oInstance.sDIVID]; 308. var frame = document.getElementById(oInstance.sFrameID); 309. frame.style.display = CalendarDiv.style.display="none"; 310.} 311.</script> 312.</head> 313.<BODY > 314.<script > 315.var oCalendarEn=new PopupCalendar("oCalendarEn"); //初始化控件时,请给出实例名称如:oCalendarEn 316.oCalendarEn.Init(); 317.var oCalendarChs=new PopupCalendar("oCalendarChs"); //初始化控件时,请给出实例名称:oCalendarChs 318.oCalendarChs.weekDaySting=new Array("日","一","二","三","四","五","六"); 319.oCalendarChs.monthSting=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"); 320.oCalendarChs.oBtnTodayTitle="今天"; 321.oCalendarChs.oBtnCancelTitle="取消"; 322.oCalendarChs.Init(); 323.</script> 324.<br><br> 325. <input readonly type="text" name="dd" id="aa" onclick="getDateString(this,oCalendarEn)" value="date"> 326.<br><br> 327. <select style="width:200"> 328.<option>test0</option> 329.<option>test1</option> 330.<option>test2</option> 331.<option>test3</option> 332.</select> 333.<br><br> 334. <input readonly type="text" name="dd33" id="aa" onclick="getDateString(this,oCalendarChs)" value="日期版"><br> <select style="width:200"> 335.<option>test0</option> 336.<option>test1</option> 337.<option>test2</option> 338.<option>test3</option> 339.</select> 340.<br><br> 341. <select style="width:200"> 342.<option>test0</option> 343.<option>test1</option> 344.<option>test2</option> 345.<option>test3</option> 346.</select> 347.</BODY> 348.</HTML> |
|||
javascript 取得table行数与列数 | http://heisetoufa.iteye.com/blog/678452 | ||
1.var table = document.getElementById("table_name"); 2. 3.var rows = table.rows.length;//行数 4.var cells = table.rows.item(0).cells.length;//列数 |