Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
785d500c
Commit
785d500c
authored
Jul 26, 2006
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made some changes to the form plugin, to simplify it and bring it up to date.
parent
6e868bb0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
44 deletions
+21
-44
form.js
form/form.js
+21
-44
No files found.
form/form.js
View file @
785d500c
...
@@ -44,18 +44,17 @@
...
@@ -44,18 +44,17 @@
$
.
fn
.
ajaxSubmit
=
function
(
target
,
post_cb
,
pre_cb
,
url
,
mth
)
{
$
.
fn
.
ajaxSubmit
=
function
(
target
,
post_cb
,
pre_cb
,
url
,
mth
)
{
if
(
!
this
.
vars
)
this
.
serialize
();
if
(
!
this
.
vars
)
this
.
serialize
();
if
(
pre_cb
&&
pre_cb
.
constructor
==
Function
)
if
(
pre_cb
&&
pre_cb
.
constructor
==
Function
&&
pre_cb
(
this
.
vars
)
===
false
)
return
;
if
(
pre_cb
(
this
.
vars
)
===
false
)
return
;
var
f
=
this
.
get
(
0
);
var
f
=
this
.
get
(
0
);
var
url
=
url
||
f
.
action
||
''
;
var
url
=
url
||
f
.
action
||
''
;
var
mth
=
mth
||
f
.
method
||
'POST'
;
var
mth
=
mth
||
f
.
method
||
'POST'
;
if
(
target
&&
target
.
constructor
==
Function
)
{
if
(
target
&&
target
.
constructor
==
Function
)
$
.
ajax
(
mth
,
url
,
$
.
param
(
this
.
vars
),
target
);
$
.
ajax
(
mth
,
url
,
$
.
param
(
this
.
vars
),
target
);
}
else
if
(
target
&&
target
.
constructor
==
String
)
{
else
if
(
target
&&
target
.
constructor
==
String
)
$
(
target
).
load
(
url
,
this
.
vars
,
post_cb
);
$
(
target
).
load
(
url
,
this
.
vars
,
post_cb
);
}
else
{
else
{
this
.
vars
.
push
({
name
:
'evaljs'
,
value
:
1
});
this
.
vars
.
push
({
name
:
'evaljs'
,
value
:
1
});
$
.
ajax
(
mth
,
url
,
$
.
param
(
this
.
vars
),
function
(
r
)
{
$
.
ajax
(
mth
,
url
,
$
.
param
(
this
.
vars
),
function
(
r
)
{
eval
(
r
.
responseText
);
eval
(
r
.
responseText
);
...
@@ -104,13 +103,14 @@ $.fn.ajaxSubmit = function(target, post_cb, pre_cb, url, mth) {
...
@@ -104,13 +103,14 @@ $.fn.ajaxSubmit = function(target, post_cb, pre_cb, url, mth) {
* @param post_cb callback after any results are returned
* @param post_cb callback after any results are returned
* @param pre_cb callback function before submission
* @param pre_cb callback function before submission
* @return the jQuery Object
* @return the jQuery Object
* @type jQuery
* @see serialize(), ajaxSubmit()
* @see serialize(), ajaxSubmit()
* @author Mark Constable (markc@renta.net)
* @author Mark Constable (markc@renta.net)
* @author G. vd Hoven, Mike Alsup, Sam Collett, John Resig
* @author G. vd Hoven, Mike Alsup, Sam Collett, John Resig
*/
*/
$
.
fn
.
ajaxForm
=
function
(
target
,
post_cb
,
pre_cb
)
{
$
.
fn
.
ajaxForm
=
function
(
target
,
post_cb
,
pre_cb
)
{
return
this
.
each
(
function
(){
return
this
.
each
(
function
(){
$
(
'input[@type="submit"],input[@type="image"]'
,
this
).
click
(
function
(
ev
){
$
(
"input[@type=submit],input[@type=image]"
,
this
).
click
(
function
(
ev
){
this
.
form
.
clicked
=
this
;
this
.
form
.
clicked
=
this
;
if
(
ev
.
offsetX
!=
undefined
)
{
if
(
ev
.
offsetX
!=
undefined
)
{
this
.
form
.
clicked_x
=
ev
.
offsetX
;
this
.
form
.
clicked_x
=
ev
.
offsetX
;
...
@@ -121,25 +121,11 @@ $.fn.ajaxForm = function(target, post_cb, pre_cb) {
...
@@ -121,25 +121,11 @@ $.fn.ajaxForm = function(target, post_cb, pre_cb) {
}
}
});
});
}).
submit
(
function
(
e
){
}).
submit
(
function
(
e
){
e
.
preventDefault
();
$
(
this
).
ajaxSubmit
(
target
,
post_cb
,
pre_cb
);
$
(
this
).
ajaxSubmit
(
target
,
post_cb
,
pre_cb
);
return
false
;
return
false
;
});
});
};
};
/*
$.ajax({
type: "POST",
url: "foo.cgi",
data: $.param( $("form").formdata() ),
success: function(){},
error: function(){},
complete: function(){}
});
*/
/**
/**
* A simple wrapper function that sits around the .serialize()
* A simple wrapper function that sits around the .serialize()
* method, allowing you to easily extract the data stored within
* method, allowing you to easily extract the data stored within
...
@@ -151,6 +137,7 @@ $.ajax({
...
@@ -151,6 +137,7 @@ $.ajax({
* $.param( $("form").formdata() );
* $.param( $("form").formdata() );
*
*
* @return An array of name/value pairs representing the form
* @return An array of name/value pairs representing the form
* @type Array<Object>
* @see serialize()
* @see serialize()
# @author John Resig
# @author John Resig
*/
*/
...
@@ -178,6 +165,7 @@ $.fn.formdata = function(){
...
@@ -178,6 +165,7 @@ $.fn.formdata = function(){
* $('#form-id').serialize().some_other_plugin();
* $('#form-id').serialize().some_other_plugin();
*
*
* @return the jQuery Object
* @return the jQuery Object
* @return jQuery
* @see ajaxForm(), ajaxSubmit()
* @see ajaxForm(), ajaxSubmit()
* @author Mark Constable (markc@renta.net)
* @author Mark Constable (markc@renta.net)
* @author G. vd Hoven, Mike Alsup, Sam Collett, John Resig
* @author G. vd Hoven, Mike Alsup, Sam Collett, John Resig
...
@@ -187,32 +175,21 @@ $.fn.serialize = function() {
...
@@ -187,32 +175,21 @@ $.fn.serialize = function() {
var
ok
=
{
INPUT
:
true
,
TEXTAREA
:
true
,
OPTION
:
true
};
var
ok
=
{
INPUT
:
true
,
TEXTAREA
:
true
,
OPTION
:
true
};
$
(
'*'
,
this
).
each
(
function
()
{
$
(
'*'
,
this
).
each
(
function
()
{
if
(
this
.
disabled
||
this
.
type
==
'reset'
||
(
this
.
type
==
'checkbox'
&&
!
this
.
checked
)
||
(
this
.
type
==
'radio'
&&
!
this
.
checked
))
return
;
if
(
this
.
type
==
'submit'
||
this
.
type
==
'image'
)
{
if
(
this
.
form
.
clicked
!=
this
)
return
;
if
(
this
.
type
==
'image'
)
{
if
(
this
.
form
.
clicked_x
)
{
a
.
push
({
name
:
this
.
name
+
'_x'
,
value
:
this
.
form
.
clicked_x
});
a
.
push
({
name
:
this
.
name
+
'_y'
,
value
:
this
.
form
.
clicked_y
});
return
;
}
}
}
if
(
!
ok
[
this
.
nodeName
.
toUpperCase
()])
return
;
var
par
=
this
.
parentNode
;
var
par
=
this
.
parentNode
;
var
p
=
par
.
nodeName
.
toUpperCase
();
var
p
=
par
.
nodeName
.
toUpperCase
();
if
((
p
==
'SELECT'
||
p
==
'OPTGROUP'
)
&&
!
this
.
selected
)
return
;
var
n
=
this
.
name
||
p
==
'OPTGROUP'
&&
par
.
parentNode
.
name
||
p
==
'SELECT'
&&
par
.
name
||
this
.
id
;
var
n
=
this
.
name
;
if
(
!
n
||
this
.
disabled
||
this
.
type
==
'reset'
||
if
(
!
n
)
n
=
(
p
==
'OPTGROUP'
)
?
par
.
parentNode
.
name
:
(
p
==
'SELECT'
)
?
par
.
name
:
this
.
name
;
(
this
.
type
==
'checkbox'
||
this
.
type
==
'radio'
)
&&
!
this
.
checked
||
if
(
n
==
undefined
)
return
;
!
ok
[
this
.
nodeName
.
toUpperCase
()]
||
(
this
.
type
==
'submit'
||
this
.
type
==
'image'
)
&&
this
.
form
.
clicked
!=
this
||
(
p
==
'SELECT'
||
p
==
'OPTGROUP'
)
&&
!
this
.
selected
)
return
;
if
(
this
.
type
==
'image'
&&
this
.
form
.
clicked_x
)
return
a
.
push
(
{
name
:
this
.
name
+
'_x'
,
value
:
this
.
form
.
clicked_x
},
{
name
:
this
.
name
+
'_y'
,
value
:
this
.
form
.
clicked_y
}
);
a
.
push
({
name
:
n
,
value
:
this
.
value
});
a
.
push
({
name
:
n
,
value
:
this
.
value
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment