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
c8b7881c
Commit
c8b7881c
authored
Jan 16, 2007
by
Jörn Zaefferer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhanced attr(String, Function) to pass through index of current element
parent
8b51bfbd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
coreTest.js
src/jquery/coreTest.js
+2
-1
jquery.js
src/jquery/jquery.js
+10
-4
No files found.
src/jquery/coreTest.js
View file @
c8b7881c
...
@@ -82,8 +82,9 @@ test("attr(String)", function() {
...
@@ -82,8 +82,9 @@ test("attr(String)", function() {
});
});
test
(
"attr(String, Function)"
,
function
()
{
test
(
"attr(String, Function)"
,
function
()
{
expect
(
1
);
expect
(
2
);
ok
(
$
(
'#text1'
).
attr
(
'value'
,
function
()
{
return
this
.
id
})[
0
].
value
==
"text1"
,
"Set value from id"
);
ok
(
$
(
'#text1'
).
attr
(
'value'
,
function
()
{
return
this
.
id
})[
0
].
value
==
"text1"
,
"Set value from id"
);
ok
(
$
(
'#text1'
).
attr
(
'title'
,
function
(
i
)
{
return
i
}).
attr
(
'title'
)
==
"0"
,
"Set value with an index"
);
});
});
test
(
"attr(Hash)"
,
function
()
{
test
(
"attr(Hash)"
,
function
()
{
...
...
src/jquery/jquery.js
View file @
c8b7881c
...
@@ -411,10 +411,16 @@ jQuery.fn = jQuery.prototype = {
...
@@ -411,10 +411,16 @@ jQuery.fn = jQuery.prototype = {
* @result <img src="test.jpg" title="test.jpg" />
* @result <img src="test.jpg" title="test.jpg" />
* @desc Sets title attribute from src attribute.
* @desc Sets title attribute from src attribute.
*
*
* @example $("img").attr("title", function(index) { return this.title + (i + 1); });
* @before <img title="pic" /><img title="pic" /><img title="pic" />
* @result <img title="pic1" /><img title="pic2" /><img title="pic3" />
* @desc Enumerate title attribute.
*
* @name attr
* @name attr
* @type jQuery
* @type jQuery
* @param String key The name of the property to set.
* @param String key The name of the property to set.
* @param Function value A function returning the value to set.
* @param Function value A function returning the value to set.
* Scope: Current element, argument: Index of current element
* @cat DOM/Attributes
* @cat DOM/Attributes
*/
*/
attr
:
function
(
key
,
value
,
type
)
{
attr
:
function
(
key
,
value
,
type
)
{
...
@@ -430,12 +436,12 @@ jQuery.fn = jQuery.prototype = {
...
@@ -430,12 +436,12 @@ jQuery.fn = jQuery.prototype = {
}
}
// Check to see if we're setting style values
// Check to see if we're setting style values
return
this
.
each
(
function
(){
return
this
.
each
(
function
(
index
){
// Set all the styles
// Set all the styles
for
(
var
prop
in
obj
)
for
(
var
prop
in
obj
)
jQuery
.
attr
(
jQuery
.
attr
(
type
?
this
.
style
:
this
,
type
?
this
.
style
:
this
,
prop
,
jQuery
.
prop
(
this
,
obj
[
prop
],
type
)
prop
,
jQuery
.
prop
(
this
,
obj
[
prop
],
type
,
index
)
);
);
});
});
},
},
...
@@ -1256,10 +1262,10 @@ jQuery.extend({
...
@@ -1256,10 +1262,10 @@ jQuery.extend({
return
obj
;
return
obj
;
},
},
prop
:
function
(
elem
,
value
,
type
){
prop
:
function
(
elem
,
value
,
type
,
index
){
// Handle executable functions
// Handle executable functions
if
(
jQuery
.
isFunction
(
value
)
)
if
(
jQuery
.
isFunction
(
value
)
)
return
value
.
call
(
elem
);
return
value
.
call
(
elem
,
[
index
]
);
// Handle passing in a number to a CSS property
// Handle passing in a number to a CSS property
if
(
value
.
constructor
==
Number
&&
type
==
"curCSS"
)
if
(
value
.
constructor
==
Number
&&
type
==
"curCSS"
)
...
...
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