Convenient setting functions
For most of the jquery1.4 setting values, you can set the second parameter as the callback function. For example:. CSS (),. ATTR (),. Val (),. html (),. Text ().
This is very abstract, let's look at the example http://demo.jb51.net/js/jquery1.4/jquery_1.htm
<textarea id="runcode29824"></textarea> Xmlns = "http://www.w3.org/1999/xhtml">
Improvement 1: For most of the jquery1.4 setting values, you can set the second parameter as the callback function. For example:. CSS (),. ATTR (),. Val (),. html (),. Text ().
See the demo below.
This is a link.
Now, use the callback function to directly replace the text in the link. The previous method is to first take the htnl of A, then use regular expression matching, and finally replace it.
Step 1. Let's see.Code:
Functions ('{a1'}.html (function (I, HTML ){
Return html. Replace (/. /G ,'! Replaced ');
});
You will find that ". "Replaced "! Already replaced ".
Is it more convenient than before?
It is also applicable to other setting value pairs, such as ATTR (). You can try to change the second parameter to a function.
This replacement Link's title attribute:
$ ('# A1'). ATTR ("title", function (I, Title ){
Return title + "(replaced )";
});