vickzhu

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            151 隨筆 :: 0 文章 :: 34 評論 :: 0 Trackbacks
          得到當前元素并改變背景色:
                   <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 筱 筱 閱讀(1752) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 上犹县| 龙口市| 宁波市| 玉林市| 澄城县| 营口市| 龙口市| 区。| 栾川县| 呈贡县| 辽宁省| 樟树市| 陇南市| 邢台县| 胶南市| 湘潭县| 宜君县| 周至县| 惠水县| 海南省| 周口市| 长葛市| 莱芜市| 辽宁省| 浙江省| 开鲁县| 陇西县| 怀集县| 额尔古纳市| 光泽县| 德惠市| 合作市| 金寨县| 固原市| 中牟县| 永寿县| 东辽县| 莒南县| 雅江县| 塔城市| 朝阳市|