用链接改变特定区域的背景及其它CSS样式的变换 - 中国WEB开发者网络 (http://www.webasp.net) -- 网页特效 (http://www.webasp.net/javascript/) --- 用链接改变特定区域的背景及其它CSS样式的变换 (http://www.webasp.net/javascript/1/523.htm) |
| -- 发布日期: 2005-06-16 |
| <!-- 网页特效代码由[中国WEB开发者网络:http://www.ChinaWebDev.com]提供! --> <!-- 要实现此效果需要 1 个步骤: --> <!-- 第 1 步: --> <!-- 把下面的代码加到<BODY></BODY>区域中: --> <script language="JavaScript" type="text/JavaScript"> <!-- Begin function showNewColor() { // setup vars var defaultColor = "white"; var newColor = "#ff9999"; if((document.getElementById)&& (document.getElementById('tagID')!=null)) { // Get a reference to the element var myElement = document.getElementById('tagID'); // Check the element's style object and background property are available if ((myElement.style)&& (myElement.style.backgroundColor!=null)) { // Check the value of the property if(myElement.style.backgroundColor == 'white'){ // change style to new color document.getElementById('tagID').style.backgroundColor = newColor; }else { // change style to default color document.getElementById('tagID').style.backgroundColor = defaultColor; } }else { // This CSS property is not assigned or is not supported return; } }else { return; } } // End ---> </script> <table id="tagID" style="background-color:white;" width="200" height="50" cellspacing="2" cellpadding="2"> <tr><td>这里是具体的内容 </td></tr> </table> <br><a href="javascript:showNewColor();">变换背景色</a> |
| webasp.net |