Ô´ÂëÍø,Ô´ÂëÂÛ̳,Ô´ÂëÖ®¼Ò,ÉÌÒµÔ´Âë,ÓÎÏ·Ô´ÂëÏÂÔØ,discuz²å¼þ,ÆåÅÆÔ´ÂëÏÂÔØ,¾«Æ·Ô´ÂëÂÛ̳

 ÕÒ»ØÃÜÂë
 Á¢¼´×¢²á
Â¥Ö÷: ttx9n

[JavaScript] jquery ѧϰ֮¶þ ÊôÐÔÏà¹Ø

[¸´ÖÆÁ´½Ó]

7Íò

Ö÷Ìâ

861

»ØÌû

32Íò

»ý·Ö

ÂÛ̳ԪÀÏ

Rank: 8Rank: 8

»ý·Ö
329525
·¢±íÓÚ 2010-11-23 16:54:41 | ÏÔʾȫ²¿Â¥²ã |ÔĶÁģʽ
jquery ѧϰ֮¶þ ÊôÐÔÏà¹Ø×ÊÁÏ£¬Ñ§Ï°jqueryµÄÅóÓÑ¿ÉÒԲο¼Ï¡£ attr(name)
È¡µÃµÚÒ»¸öÆ¥ÅäÔªËصÄÊôÐÔÖµ¡£Í¨¹ýÕâ¸ö·½·¨¿ÉÒÔ·½±ãµØ´ÓµÚÒ»¸öÆ¥ÅäÔªËØÖлñÈ¡Ò»¸öÊôÐÔµÄÖµ¡£Èç¹ûÔªËØûÓÐÏàÓ¦ÊôÐÔ£¬Ôò·µ»Ø undefined ¡£
Access a property on the first matched element. This method makes it easy to retrieve a property value from the first matched element. If the element does not have an attribute with such a name, undefined is returned.
·µ»ØÖµ
Object

²ÎÊý
name (String) : ÊôÐÔÃû³Æ

ʾÀý
·µ»ØÎĵµÖеÚÒ»¸öͼÏñµÄsrcÊôÐÔÖµ¡£

HTML ´úÂë:

<img src="test.jpg"/>
jQuery ´úÂë:

$("img").attr("src");
½á¹û:

test.jpg
---------------------------------------------------------------------------------------------------------------------------------------
attr(properties)
½«Ò»¸ö¡°Ãû/Öµ¡±ÐÎʽµÄ¶ÔÏóÉèÖÃΪËùÓÐÆ¥ÅäÔªËصÄÊôÐÔ¡£
ÕâÊÇÒ»ÖÖÔÚËùÓÐÆ¥ÅäÔªËØÖÐÅúÁ¿ÉèÖúܶàÊôÐÔµÄ×î¼Ñ·½Ê½¡£ ×¢Ò⣬Èç¹ûÄãÒªÉèÖöÔÏóµÄclassÊôÐÔ£¬Äã±ØÐëʹÓÃ'className' ×÷ΪÊôÐÔÃû¡£»òÕßÄã¿ÉÒÔÖ±½ÓʹÓÃ.addClass( class ) ºÍ .removeClass( class ).
Set a key/value object as properties to all matched elements.
This serves as the best way to set a large number of properties on all matched elements. Note that you must use 'className' as key if you want to set the class-Attribute. Or use .addClass( class ) or .removeClass( class ).
·µ»ØÖµ
jQuery

²ÎÊý
properties (Map) : ×÷ΪÊôÐԵġ°Ãû/Öµ¶Ô¡±¶ÔÏó

ʾÀý
ΪËùÓÐͼÏñÉèÖÃsrcºÍaltÊôÐÔ¡£

HTML ´úÂë:

<img/>
jQuery ´úÂë:

$("img").attr({ src: "test.jpg", alt: "Test Image" });
½á¹û:

[ <img src= "test.jpg" alt:="Test Image" /> ]
---------------------------------------------------------------------------------------------------------------------------------------
attr(key,value)
ΪËùÓÐÆ¥ÅäµÄÔªËØÉèÖÃÒ»¸öÊôÐÔÖµ¡£
Set a single property to a value, on all matched elements.
·µ»ØÖµ
jQuery

²ÎÊý
key (String) : ÊôÐÔÃû³Æ

value (Object) : ÊôÐÔÖµ

ʾÀý
ΪËùÓÐͼÏñÉèÖÃsrcÊôÐÔ¡£

HTML ´úÂë:

<img/>
<img/>
jQuery ´úÂë:

$("img").attr("src","test.jpg");
½á¹û:

[ <img src= "test.jpg" /> , <img src= "test.jpg" /> ]
---------------------------------------------------------------------------------------------------------------------------------------
attr(key,fn)
ΪËùÓÐÆ¥ÅäµÄÔªËØÉèÖÃÒ»¸ö¼ÆËãµÄÊôÐÔÖµ¡£
²»Ìṩֵ£¬¶øÊÇÌṩһ¸öº¯Êý£¬ÓÉÕâ¸öº¯Êý¼ÆËãµÄÖµ×÷ΪÊôÐÔÖµ¡£
Set a single property to a computed value, on all matched elements.
Instead of supplying a string value as described 'above', a function is provided that computes the value.
·µ»ØÖµ
jQuery

²ÎÊý
key (String) : ÊôÐÔÃû³Æ

fn (Function) : ·µ»ØÖµµÄº¯Êý ·¶Î§:µ±Ç°ÔªËØ, ²ÎÊý: µ±Ç°ÔªËصÄË÷ÒýÖµ

ʾÀý
°ÑsrcÊôÐÔµÄÖµÉèÖÃΪtitleÊôÐÔµÄÖµ¡£

HTML ´úÂë:

<img src="test.jpg"/>
jQuery ´úÂë:

$("img").attr("title", function() { return this.src });
½á¹û:

<img src="test.jpg" title="test.jpg" />
---------------------------------------------------------------------------------------------------------------------------------------
removeAttr(name)
´Óÿһ¸öÆ¥ÅäµÄÔªËØÖÐɾ³ýÒ»¸öÊôÐÔ
Remove an attribute from each of the matched elements.
·µ»ØÖµ
jQuery

²ÎÊý
name (String) : Ҫɾ³ýµÄÊôÐÔÃû

ʾÀý
½«ÎĵµÖÐͼÏñµÄsrcÊôÐÔɾ³ý

HTML ´úÂë:

<img src="test.jpg"/>
jQuery ´úÂë:

$("img").removeAttr("src");
½á¹û:

[ <img /> ]
»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

0

Ö÷Ìâ

1Íò

»ØÌû

0

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
0
·¢±íÓÚ 2023-1-5 05:01:07 | ÏÔʾȫ²¿Â¥²ã
ÅÂÅÂÅÂÅÂÅÂÅÂÅÂÅÂÅÂÅÂÅÂÅÂÅÂÅÂ

4

Ö÷Ìâ

2Íò

»ØÌû

107

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
107
·¢±íÓÚ 2023-3-4 17:15:43 | ÏÔʾȫ²¿Â¥²ã
8888888888888888

0

Ö÷Ìâ

2Íò

»ØÌû

87

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
87
·¢±íÓÚ 2023-9-8 14:08:19 | ÏÔʾȫ²¿Â¥²ã
¶ø¿ìÀÖÄãÃÇ¿ìÀÖÂíÄê¿ìÀÖ

0

Ö÷Ìâ

2Íò

»ØÌû

0

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
0
·¢±íÓÚ 2023-10-12 07:13:26 | ÏÔʾȫ²¿Â¥²ã
¿´µ½ÕâÌû×ÓÕæÊǸßÐË£¡

6

Ö÷Ìâ

1Íò

»ØÌû

174

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
174
·¢±íÓÚ 2023-12-1 12:46:09 | ÏÔʾȫ²¿Â¥²ã
2222222222222222

0

Ö÷Ìâ

2Íò

»ØÌû

0

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
0
·¢±íÓÚ 2024-2-26 11:23:13 | ÏÔʾȫ²¿Â¥²ã
ÄãÃÇË­¿´ÁËŪÈ÷ÁË¿ÉÄÜ

1

Ö÷Ìâ

2Íò

»ØÌû

319

»ý·Ö

Ö춻áÔ±

Rank: 3Rank: 3

»ý·Ö
319
·¢±íÓÚ 2024-3-20 15:57:53 | ÏÔʾȫ²¿Â¥²ã
¿ÉÒÔ£¬¿´¿¨°Í

1

Ö÷Ìâ

1Íò

»ØÌû

51

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
51
·¢±íÓÚ 2024-5-19 14:15:37 | ÏÔʾȫ²¿Â¥²ã
66666666666666666666

4

Ö÷Ìâ

1Íò

»ØÌû

60

»ý·Ö

×¢²á»áÔ±

Rank: 2

»ý·Ö
60
·¢±íÓÚ 2024-6-12 19:26:40 | ÏÔʾȫ²¿Â¥²ã
ЦÄÉÁËÀÏ°å
¸ß¼¶Ä£Ê½
B Color Image Link Quote Code Smilies

±¾°æ»ý·Ö¹æÔò

ÊÖ»ú°æ|СºÚÎÝ|ÍøÕ¾µØͼ|Ô´ÂëÂÛ̳ ( º£Íâ°æ )

GMT+8, 2025-1-20 03:34 , Processed in 0.092995 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí