閱讀1015 返回首頁    go 汽車大全


JavaScript+CSS實現表格動態樣式

效果如圖:

實現代碼:

<style> table.formdata/*表格樣式*/ { border:1px solid #5F6F7E; border-collapse:collapse;/*表格相鄰邊被合並 */ font-family:微軟雅黑; font-size:10px; padding:2px; } </style> <script type="text/javascript"> function hilite(obj) { //選擇包含<input>的<td>標記 obj = document.getElementById("td"+obj.id.toString()); obj.style.border = '2px solid #007EFF'; //加粗、變色 } function delite(obj) { obj = document.getElementById("td"+obj.id.toString()); obj.style.border = '0px solid #ABABAB'; //恢複回原來的邊框 } </script> <table > <tr> <th></th> <th>2004</th> <th>2005</th> <th>2006</th> </tr> <tr> <tr><!--onFocus聚焦時,onBlur當光標離開時的事件;注意:td單元格的id比文本框的id多一個“td”,正是這樣才能選擇到包含<input>的<td>標記--> <th >張三</th> <td ><input type="text" onFocus="hilite(this);" onBlur="delite(this);"></td> <td ><input type="text" onFocus="hilite(this);" onBlur="delite(this);"></td> <td ><input type="text" onFocus="hilite(this);" onBlur="delite(this);"></td> </tr> <tr> <th>李四</th> <td ><input type="text" onFocus="hilite(this);" onBlur="delite(this);"></td> <td ><input type="text" onFocus="hilite(this);" onBlur="delite(this);"></td> <td ><input type="text" onFocus="hilite(this);" onBlur="delite(this);"></td> </tr> <tr> <th>王五</th> <td ><input type="text" onFocus="hilite(this);" onBlur="delite(this);"></td> <td ><input type="text" onFocus="hilite(this);" onBlur="delite(this);"></td> <td ><input type="text" onFocus="hilite(this);" onBlur="delite(this);"></td> </tr> </table>

最後更新:2017-04-02 03:42:39

  上一篇:go CSS樣式選擇器
  下一篇:go ASP.NET網頁文本編輯器的使用