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
789f0e10
Commit
789f0e10
authored
Jan 08, 2007
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.text( String ) now works as you'd expect it to, plus it's much faster and smaller - which is good.
parent
d0e8a245
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
21 deletions
+11
-21
coreTest.js
src/jquery/coreTest.js
+2
-2
jquery.js
src/jquery/jquery.js
+9
-19
No files found.
src/jquery/coreTest.js
View file @
789f0e10
...
...
@@ -433,7 +433,7 @@ test("removeAttr(String", function() {
ok
(
$
(
'#mark'
).
removeAttr
(
"class"
)[
0
].
className
==
""
,
"remove class"
);
});
test
(
"text(String, Boolean)"
,
function
()
{
test
(
"text(String)"
,
function
()
{
expect
(
1
);
ok
(
$
(
"#foo"
).
text
(
"<div><b>Hello</b> cruel world!</div>"
)[
0
].
innerHTML
==
"<div><b>Hello</b> cruel world!</div>"
,
"Check escaped text"
);
ok
(
$
(
"#foo"
).
text
(
"<div><b>Hello</b> cruel world!</div>"
,
true
)[
0
].
innerHTML
==
"Hello cruel world!"
,
"Check stripped text"
);
});
src/jquery/jquery.js
View file @
789f0e10
...
...
@@ -528,10 +528,8 @@ jQuery.fn = jQuery.prototype = {
/**
* Set the text contents of all matched elements.
*
* Similar to html(), but escapes HTML (replace "<" and ">" with their
* HTML entities.
*
* If stripTags argument is set to true, HTML is stripped.
* Similar to html(), but escapes HTML (replace "<" and ">" with their
* HTML entities).
*
* @example $("p").text("<b>Some</b> new text.");
* @before <p>Test Paragraph.</p>
...
...
@@ -546,23 +544,15 @@ jQuery.fn = jQuery.prototype = {
* @name text
* @type String
* @param String val The text value to set the contents of the element to.
* @param Boolean stripTags (optional) Wheather to strip or only escape tags
* @cat DOM/Attributes
*/
text
:
function
(
e
,
stripTags
)
{
if
(
typeof
e
==
"string"
)
return
this
.
html
(
stripTags
?
e
.
replace
(
/<
\/?[^
>
]
+>/gi
,
''
)
:
e
.
replace
(
/</g
,
"<"
).
replace
(
/>/g
,
">"
)
);
e
=
e
||
this
;
var
t
=
""
;
for
(
var
j
=
0
,
el
=
e
.
length
;
j
<
el
;
j
++
)
{
var
r
=
e
[
j
].
childNodes
;
for
(
var
i
=
0
,
rl
=
r
.
length
;
i
<
rl
;
i
++
)
if
(
r
[
i
].
nodeType
!=
8
)
t
+=
r
[
i
].
nodeType
!=
1
?
r
[
i
].
nodeValue
:
jQuery
.
fn
.
text
([
r
[
i
]
]);
}
return
t
;
text
:
function
(
e
)
{
var
type
=
this
.
length
&&
this
[
0
].
innerText
==
undefined
?
"textContent"
:
"innerText"
;
return
e
==
undefined
?
this
.
length
&&
this
[
0
][
type
]
:
this
.
each
(
function
(){
this
[
type
]
=
e
;
});
},
/**
...
...
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