返回到:Prototype – 表单管理
此方法返回表单中所有表单控件的集合。
注– 结果中不包含 OPTION 元素;只有它们的父 SELECT 控件是。
语法
form.getElements();
返回值
它返回一个 HTMLFormElement 数组。
例子
HTML
x
47
47
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
var form = $('example');
9
var arr = form.getElements();
10
arr.each(function(item) {
11
alert("Return Element : " + item.inspect());
12
});
13
}
14
</script>
15
</head>
16
17
<body>
18
<p>Click the button to see the result.</p>
19
<br />
20
21
<form id = "example" action = "#" onsubmit = "return false">
22
<fieldset>
23
<legend>User info</legend>
24
<div>
25
<label for = "username">Username:</label>
26
<input name = "username" id = "username" value = "Sulien" type = "text">
27
</div>
28
<div>
29
<label for = "age">Age:</label>
30
<input name = "age" id = "age" value = "23" size = "3" type = "text">
31
</div>
32
<div>
33
<label for = "hobbies">Your hobbies are:</label>
34
<select name = "hobbies" id = "hobbies" multiple = "multiple">
35
<option>coding</option>
36
<option>swimming</option>
37
<option>hiking</option>
38
<option>drawing</option>
39
</select>
40
</div>
41
</fieldset>
42
</form>
43
<br />
44
45
<input type = "button" value = "Result" onclick = "showResult();"/>
46
</body>
47
</html>
返回到:Prototype – 表单管理
阅读剩余 60%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8516.html