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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 大理市| 五常市| 沽源县| 浠水县| 滨州市| 庆安县| 睢宁县| 石柱| 万源市| 兴隆县| 灵川县| 无极县| 富民县| 莫力| 仙桃市| 个旧市| 海安县| 海盐县| 安龙县| 聂拉木县| 泌阳县| 石首市| 白朗县| 叶城县| 马公市| 伊宁市| 灌阳县| 东兴市| 桐柏县| 临沂市| 辽宁省| 高邑县| 忻城县| 盘锦市| 嵊泗县| 玉林市| 顺平县| 永福县| 平凉市| 太仓市| 都匀市|