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
5acecf6e
Commit
5acecf6e
authored
Jan 07, 2007
by
Jörn Zaefferer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented #756, making text(String) really useful
parent
c78b1fb9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
7 deletions
+20
-7
ChangeLog.txt
ChangeLog.txt
+1
-0
coreTest.js
src/jquery/coreTest.js
+4
-0
jquery.js
src/jquery/jquery.js
+15
-7
No files found.
ChangeLog.txt
View file @
5acecf6e
...
@@ -27,6 +27,7 @@ New and Noteworthy
...
@@ -27,6 +27,7 @@ New and Noteworthy
- Improved docs for append, prepend, before and after, merging the three pairs into one
- Improved docs for append, prepend, before and after, merging the three pairs into one
- Improved show/hide animations to show only hidden and hide only visible elements
- Improved show/hide animations to show only hidden and hide only visible elements
- Added attr(String,Function) to calculate the value and support for attr("key", "${formula}") syntax, a shortcut for the former
- Added attr(String,Function) to calculate the value and support for attr("key", "${formula}") syntax, a shortcut for the former
- text(String) now escapes HTML per default and optionally stris tags completely
1.0.4
1.0.4
-----
-----
...
...
src/jquery/coreTest.js
View file @
5acecf6e
...
@@ -435,3 +435,7 @@ test("removeAttr(String", function() {
...
@@ -435,3 +435,7 @@ test("removeAttr(String", function() {
ok
(
$
(
'#mark'
).
removeAttr
(
"class"
)[
0
].
className
==
""
,
"remove class"
);
ok
(
$
(
'#mark'
).
removeAttr
(
"class"
)[
0
].
className
==
""
,
"remove class"
);
});
});
test
(
"text(String, Boolean)"
,
function
()
{
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"
);
});
\ No newline at end of file
src/jquery/jquery.js
View file @
5acecf6e
...
@@ -526,10 +526,19 @@ jQuery.fn = jQuery.prototype = {
...
@@ -526,10 +526,19 @@ jQuery.fn = jQuery.prototype = {
*/
*/
/**
/**
* Set the text contents of all matched elements. This has the same
* Set the text contents of all matched elements.
* effect as html().
*
*
* @example $("p").text("Some new text.");
* Similar to html(), but escapes HTML (replace "<" and ">" with their
* HTML entities.
*
* If stripTags argument is set to true, HTML is stripped.
*
* @example $("p").text("<b>Some</b> new text.");
* @before <p>Test Paragraph.</p>
* @result <p><b>Some</b> new text.</p>
* @desc Sets the text of all paragraphs.
*
* @example $("p").text("<b>Some</b> new text.", true);
* @before <p>Test Paragraph.</p>
* @before <p>Test Paragraph.</p>
* @result <p>Some new text.</p>
* @result <p>Some new text.</p>
* @desc Sets the text of all paragraphs.
* @desc Sets the text of all paragraphs.
...
@@ -537,13 +546,12 @@ jQuery.fn = jQuery.prototype = {
...
@@ -537,13 +546,12 @@ jQuery.fn = jQuery.prototype = {
* @name text
* @name text
* @type String
* @type String
* @param String val The text value to set the contents of the element to.
* @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
* @cat DOM/Attributes
*/
*/
text
:
function
(
e
)
{
text
:
function
(
e
,
stripTags
)
{
// A surprisingly high number of people expect the
// .text() method to do this, so lets do it!
if
(
typeof
e
==
"string"
)
if
(
typeof
e
==
"string"
)
return
this
.
html
(
e
);
return
this
.
html
(
stripTags
?
e
.
replace
(
/<
\/?[^
>
]
+>/gi
,
''
)
:
e
.
replace
(
/</g
,
"<"
).
replace
(
/>/g
,
">"
)
);
e
=
e
||
this
;
e
=
e
||
this
;
var
t
=
""
;
var
t
=
""
;
...
...
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