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
b30af34f
Commit
b30af34f
authored
Nov 17, 2009
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for .text() on text nodes. Fixes #5525.
parent
c0847458
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
10 deletions
+15
-10
manipulation.js
src/manipulation.js
+11
-9
manipulation.js
test/unit/manipulation.js
+4
-1
No files found.
src/manipulation.js
View file @
b30af34f
...
@@ -31,19 +31,21 @@ if ( !jQuery.support.htmlSerialize ) {
...
@@ -31,19 +31,21 @@ if ( !jQuery.support.htmlSerialize ) {
jQuery
.
fn
.
extend
({
jQuery
.
fn
.
extend
({
text
:
function
(
text
)
{
text
:
function
(
text
)
{
if
(
typeof
text
!==
"object"
&&
text
!==
undefined
)
if
(
typeof
text
!==
"object"
&&
text
!==
undefined
)
{
return
this
.
empty
().
append
(
(
this
[
0
]
&&
this
[
0
].
ownerDocument
||
document
).
createTextNode
(
text
)
);
return
this
.
empty
().
append
(
(
this
[
0
]
&&
this
[
0
].
ownerDocument
||
document
).
createTextNode
(
text
)
);
}
var
ret
=
""
;
var
ret
=
""
;
jQuery
.
each
(
text
||
this
,
function
(){
jQuery
.
each
(
this
,
function
()
{
jQuery
.
each
(
this
.
childNodes
,
function
(){
// Get the text from text nodes and CDATA nodes
if
(
this
.
nodeType
!==
8
)
{
if
(
this
.
nodeType
===
3
||
this
.
nodeType
===
4
)
{
ret
+=
this
.
nodeType
!==
1
?
ret
+=
this
.
nodeValue
;
this
.
nodeValue
:
jQuery
.
fn
.
text
(
[
this
]
);
// Traverse everything else, except comment nodes
}
}
else
if
(
this
.
nodeType
!==
8
)
{
});
ret
+=
jQuery
.
fn
.
text
.
call
(
this
.
childNodes
);
}
});
});
return
ret
;
return
ret
;
...
...
test/unit/manipulation.js
View file @
b30af34f
...
@@ -4,9 +4,12 @@ var bareObj = function(value) { return value; };
...
@@ -4,9 +4,12 @@ var bareObj = function(value) { return value; };
var
functionReturningObj
=
function
(
value
)
{
return
(
function
()
{
return
value
;
});
};
var
functionReturningObj
=
function
(
value
)
{
return
(
function
()
{
return
value
;
});
};
test
(
"text()"
,
function
()
{
test
(
"text()"
,
function
()
{
expect
(
1
);
expect
(
2
);
var
expected
=
"This link has class=
\"
blog
\"
: Simon Willison's Weblog"
;
var
expected
=
"This link has class=
\"
blog
\"
: Simon Willison's Weblog"
;
equals
(
jQuery
(
'#sap'
).
text
(),
expected
,
'Check for merged text of more then one element.'
);
equals
(
jQuery
(
'#sap'
).
text
(),
expected
,
'Check for merged text of more then one element.'
);
// Check serialization of text values
equals
(
jQuery
(
document
.
createTextNode
(
"foo"
)).
text
(),
"foo"
,
"Text node was retreived from .text()."
);
});
});
var
testWrap
=
function
(
val
)
{
var
testWrap
=
function
(
val
)
{
...
...
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