2010-05-27 26 views
0

我的文檔包含多個表單。我怎樣才能使用原型獲得所有形式的數組?使用原型在java腳本中獲取一組表單

<html> 
<head></head> 
<body> 
<form id="form1"> 
    <!-- Other stuffs here --> 
</form> 
<form id="form2"> 
    <!-- Other stuffs here --> 
</form> 
<form id="form3"> 
    <!-- Other stuffs here --> 
</form> 
</body> 
</html> 

回答

3

使用原型:

$$('form') 
1

您可以使用document.forms屬性。

+0

@OP:如果你做這種方式,並希望使用任何原型上的分機上的一種形式,一定要通過'$先運行',例如不是'data = document.forms [0] .serialize();',而是'data = $(document.forms [0])。serialize();'前者將用於Firefox,Chrome和其他一些工具,但在IE上失敗。而如果你使用'$$'來完成這個工作(見Dan的答案)。要麼是完全正常,並且運作良好。 – 2010-05-27 17:30:23

相關問題