vickzhu

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            151 隨筆 :: 0 文章 :: 34 評(píng)論 :: 0 Trackbacks
          得到當(dāng)前元素并改變背景色:
                   <script type="text/javascript"> 
                       function changeColor(src){
                        var obj=document.getElementsByTagName("td");
                        for (i=0;i<obj.length;i++ ) 
                       { 
                         obj[i].style.backgroundColor="white"; 
                       }

                      src.style.backgroundColor="red";
                       src.children.tags('a')[0].style.backgroundColor="cyan";
                       alert(src.parentElement.tagName);
                       }
                      </script>

                  <table>
                      <tr>
                          <td onclick="javascript:changeColor(this)"><a>aaa</a></td>
                          <td onclick="javascirpt:changeColor(this)"><a>bbb</a></td>
                          <td onclick="javascirpt:changeColor(this)"><a>ccc</a></td>
                      </tr>
                  </table>
              

          注:改變背景圖片
                  obj[i].style.background="url(http://localhost:8080/images/abcimg.gif)";
          posted on 2008-08-04 11:15 筱 筱 閱讀(1746) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 伊金霍洛旗| 闽侯县| 水富县| 长海县| 宿松县| 哈密市| 黎平县| 汨罗市| 曲松县| 贵定县| 乌恰县| 武安市| 南安市| 香格里拉县| 佛学| 集贤县| 镇赉县| 长岛县| 青阳县| 鄄城县| 岳西县| 建瓯市| 金寨县| 米泉市| 元阳县| 上犹县| 饶河县| 衡东县| 绥滨县| 凤凰县| 舟山市| 马尔康县| 眉山市| 巢湖市| 定日县| 山丹县| 林口县| 芜湖市| 紫金县| 威远县| 西宁市|