MozTW 討論區
https://forum.moztw.org/

請問dom的w3c的標準寫法
https://forum.moztw.org/viewtopic.php?f=13&t=12092
1 頁 (共 1 頁)

發表人:  訪客 [ 2005-12-21, 00:30 ]
文章主題 :  請問dom的w3c的標準寫法

想請問一下有多個<img id="spic" widht="200">
要偵測他的寬度,在IE中寫這樣可以偵測到:

document.all.spic(0).width
document.all.spic(1).width
document.all.spic(2).width
document.all.spic(3).width
document.all.spic(4).width

可是改成getElementById就發生錯誤了,請問要如何改呢

document.getElementById("spic")(0).width
document.getElementById("spic")(1).width
document.getElementById("spic")(2).width
document.getElementById("spic")(3).width
document.getElementById("spic")(4).width

發表人:  yuoo2k [ 2005-12-21, 00:33 ]
文章主題 : 

是不是應該如下這樣?
document.getElementById("spic")[0].width
document.getElementById("spic")[1].width
document.getElementById("spic")[2].width
document.getElementById("spic")[3].width
document.getElementById("spic")[4].width
我印象中 js 的語法陣列是用 [n] 來表示...

發表人:  訪客 [ 2005-12-21, 00:39 ]
文章主題 : 

yuoo2k 寫:
是不是應該如下這樣?
document.getElementById("spic")[0].width
document.getElementById("spic")[1].width
document.getElementById("spic")[2].width
document.getElementById("spic")[3].width
document.getElementById("spic")[4].width
我印象中 js 的語法陣列是用 [n] 來表示...


嗯嗯~我都是用 [n] 來表示~不小心打太快,打錯了~Sorry :roll:

不過還是不行呢!!

發表人:  訪客 [ 2005-12-21, 02:38 ]
文章主題 : 

id 在一個 document 中是 unique 的,為什麼還會有矩陣?

發表人:  kourge [ 2005-12-21, 07:06 ]
文章主題 : 

哈哈
有幾點...
  • width 要拼對~
  • 改用 class 吧
  • 掛上 prototype library
  • 最後,用 document.getElementByClass

發表人:  訪客 [ 2005-12-21, 10:09 ]
文章主題 : 

改用
代碼:
<img name="spic" id="spic" widht="200">


代碼:
document.getElementsByName("spic").item(0)
document.getElementsByName("spic").item(1)

以下類推

發表人:  訪客 [ 2005-12-21, 10:46 ]
文章主題 : 

我改成

document.getElementsByName("spic")[count].width

這樣寫就可以了,謝謝大家的回覆 :)

1 頁 (共 1 頁) 所有顯示的時間為 UTC + 8 小時
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/