返回到:Prototype – 表单管理
此方法是一种通过Ajax.Request将表单序列化并提交到表单操作属性的 URL 的便捷方式。options 参数传递给 Ajax.Request 实例,允许覆盖 HTTP 方法并指定其他参数。
传递给 request() 的选项与底层 Ajax.Request 选项智能合并 –
- 如果表单具有方法属性,则其值用于 Ajax.Request 方法选项。如果将方法选项传递给 request(),则它优先于表单的方法属性。如果两者均未指定,则方法默认为“POST”。
- 在参数选项中指定的键值对(作为散列或查询字符串)将与(并优先于)序列化表单参数合并。
语法
formElement.request([options]);
返回值
它返回一个新的 Ajax.Request。
示例 1
考虑以下示例:
HTML
x
43
43
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function postIt() {
8
var form = $('example');
9
form.request(); //done - it's posted
10
}
11
</script>
12
</head>
13
14
<body>
15
<p>Click the button to see the result.</p>
16
<br />
17
18
<form id = "example" action = "#" onsubmit = "return false">
19
<fieldset>
20
<legend>User info</legend>
21
<div>
22
<label for = "username">Username:</label>
23
<input name = "username" id = "username" value = "Sulien" type = "text">
24
</div>
25
<div><label for = "age">Age:</label>
26
<input name = "age" id = "age" value = "23" size = "3" type = "text">
27
</div>
28
<div>
29
<label for = "hobbies">Your hobbies are:</label>
30
<select name = "hobbies" id = "hobbies" multiple = "multiple">
31
<option>coding</option>
32
<option>swimming</option>
33
<option>hiking</option>
34
<option>drawing</option>
35
</select>
36
</div>
37
</fieldset>
38
</form>
39
<br />
40
41
<input type = "button" value = "Post It" onclick = "postIt();"/>
42
</body>
43
</html>
返回到:Prototype – 表单管理
阅读剩余 86%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8509.html