1015
汽车大全
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