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
aad235b3
Commit
aad235b3
authored
Dec 12, 2012
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #13011. Let 'type' attribute be set if the browser allows.
parent
1d1c80d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
16 deletions
+7
-16
attributes.js
src/attributes.js
+2
-7
attributes.js
test/unit/attributes.js
+5
-9
No files found.
src/attributes.js
View file @
aad235b3
var
nodeHook
,
boolHook
,
fixSpecified
,
var
nodeHook
,
boolHook
,
fixSpecified
,
rclass
=
/
[\t\r\n]
/g
,
rclass
=
/
[\t\r\n]
/g
,
rreturn
=
/
\r
/g
,
rreturn
=
/
\r
/g
,
rtype
=
/^
(?:
input|button
)
$/i
,
rfocusable
=
/^
(?:
input|select|textarea|button|object
)
$/i
,
rfocusable
=
/^
(?:
input|select|textarea|button|object
)
$/i
,
rclickable
=
/^
(?:
a|area
)
$/i
,
rclickable
=
/^
(?:
a|area
)
$/i
,
rboolean
=
/^
(?:
autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected
)
$/i
,
rboolean
=
/^
(?:
autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected
)
$/i
,
...
@@ -366,13 +365,9 @@ jQuery.extend({
...
@@ -366,13 +365,9 @@ jQuery.extend({
attrHooks
:
{
attrHooks
:
{
type
:
{
type
:
{
set
:
function
(
elem
,
value
)
{
set
:
function
(
elem
,
value
)
{
// We can't allow the type property to be changed (since it causes problems in IE)
if
(
!
jQuery
.
support
.
radioValue
&&
value
===
"radio"
&&
jQuery
.
nodeName
(
elem
,
"input"
)
)
{
if
(
rtype
.
test
(
elem
.
nodeName
)
&&
elem
.
parentNode
)
{
jQuery
.
error
(
"type property can't be changed"
);
}
else
if
(
!
jQuery
.
support
.
radioValue
&&
value
===
"radio"
&&
jQuery
.
nodeName
(
elem
,
"input"
)
)
{
// Setting the type on a radio button after the value resets the value in IE6-9
// Setting the type on a radio button after the value resets the value in IE6-9
// Reset value to it's default in case type is set after value
// Reset value to default in case type is set after value during creation
// This is for element creation
var
val
=
elem
.
value
;
var
val
=
elem
.
value
;
elem
.
setAttribute
(
"type"
,
value
);
elem
.
setAttribute
(
"type"
,
value
);
if
(
val
)
{
if
(
val
)
{
...
...
test/unit/attributes.js
View file @
aad235b3
...
@@ -221,7 +221,7 @@ test( "attr(Hash)", function() {
...
@@ -221,7 +221,7 @@ test( "attr(Hash)", function() {
});
});
test
(
"attr(String, Object)"
,
function
()
{
test
(
"attr(String, Object)"
,
function
()
{
expect
(
81
);
expect
(
79
);
var
div
=
jQuery
(
"div"
).
attr
(
"foo"
,
"bar"
),
var
div
=
jQuery
(
"div"
).
attr
(
"foo"
,
"bar"
),
fail
=
false
;
fail
=
false
;
...
@@ -379,14 +379,12 @@ test( "attr(String, Object)", function() {
...
@@ -379,14 +379,12 @@ test( "attr(String, Object)", function() {
// Type
// Type
var
type
=
jQuery
(
"#check2"
).
attr
(
"type"
);
var
type
=
jQuery
(
"#check2"
).
attr
(
"type"
);
var
thrown
=
false
;
try
{
try
{
jQuery
(
"#check2"
).
attr
(
"type"
,
"hidden"
);
jQuery
(
"#check2"
).
attr
(
"type"
,
"hidden"
);
ok
(
true
,
"No exception thrown on input type change"
);
}
catch
(
e
)
{
}
catch
(
e
)
{
thrown
=
true
;
ok
(
true
,
"Exception thrown on input type change: "
+
e
)
;
}
}
ok
(
thrown
,
"Exception thrown when trying to change type property"
);
equal
(
type
,
jQuery
(
"#check2"
).
attr
(
"type"
),
"Verify that you can't change the type of an input element"
);
var
check
=
document
.
createElement
(
"input"
);
var
check
=
document
.
createElement
(
"input"
);
thrown
=
true
;
thrown
=
true
;
...
@@ -409,14 +407,12 @@ test( "attr(String, Object)", function() {
...
@@ -409,14 +407,12 @@ test( "attr(String, Object)", function() {
equal
(
"checkbox"
,
check
.
attr
(
"type"
),
"Verify that you can change the type of an input element that isn't in the DOM"
);
equal
(
"checkbox"
,
check
.
attr
(
"type"
),
"Verify that you can change the type of an input element that isn't in the DOM"
);
var
button
=
jQuery
(
"#button"
);
var
button
=
jQuery
(
"#button"
);
thrown
=
false
;
try
{
try
{
button
.
attr
(
"type"
,
"submit"
);
button
.
attr
(
"type"
,
"submit"
);
ok
(
true
,
"No exception thrown on button type change"
);
}
catch
(
e
)
{
}
catch
(
e
)
{
thrown
=
true
;
ok
(
true
,
"Exception thrown on button type change: "
+
e
)
;
}
}
ok
(
thrown
,
"Exception thrown when trying to change type property"
);
equal
(
"button"
,
button
.
attr
(
"type"
),
"Verify that you can't change the type of a button element"
);
var
$radio
=
jQuery
(
"<input>"
,
{
var
$radio
=
jQuery
(
"<input>"
,
{
"value"
:
"sup"
,
"value"
:
"sup"
,
...
...
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