我有沒有任何形式的周圍下面輸入:如何使用Prototype獲得輸入值?
<input type="text" value="myValue" name="td_website static" class="td_inner_input">
我怎樣才能與原型的輸入值?我試圖使用alert($('tb_website static').value);
,但它不起作用。
我有沒有任何形式的周圍下面輸入:如何使用Prototype獲得輸入值?
<input type="text" value="myValue" name="td_website static" class="td_inner_input">
我怎樣才能與原型的輸入值?我試圖使用alert($('tb_website static').value);
,但它不起作用。
那是因爲$()
函數是getElementById()
的別名。這意味着你需要給和ID在你輸入:)
<input type="text" value="myValue" id="td_website static" name="td_website static" class="td_inner_input">
我敢肯定,$('tb_website static')
將尋找與該ID不是名稱的元素。
您需要使用$$
函數返回一個array。有幾種方法可以使用enumerable結果。
如果你知道只會有一個匹配的元素,然後使用此:
$$('[name="tb_website static"]').first().value
如果有不止一個輸入(這是有效的HTML),那麼這得值的數組:
$$('[name="tb_website static"]').map(Form.Element.getValue)
(通過經由Form.Element.getValue
映射 - 別名爲$F
- 不他們的值存儲在一個value
屬性更好手柄瀏覽器的差異和非input
元素)
好的謝謝Jaroslav! – trouble 2011-03-08 13:38:59