How does JQ intercept the src of img in the JS string and add a parameter

for example, a JS string like this

<img src="5.jpg">

AAP5

<b>1~2</b>

<img src="4.jpg">

1get

2

<b>2~4</b>

<p style="text-align: center; "><img src="3.jpg">

:

1;

2;

3TA;

4;

5;

6""

<b>5</b>

<p style="text-align: center; "><img src="2.jpg">

5:

1;

2;

39

<p style="text-align: center; "><img src="1.jpg">

TA

<br>

I want to extract the src, of all the img inside and add a parameter to it after the jpg, such as ? Xmurosq processing imagehand resizeMagime 500

.

is there any other way to do it if you don"t use rules?

Mar.29,2021

No regular but string traversal. By the way, it's convenient to use regularization, so why not allow it?


be ugly without regularization

var jsStr = '';

var size = "?x-oss-process=image/resize,h_500";
var result = jsStr;
while(result.indexOf('.jpg"') > -1 || result.indexOf('.png"') >-1) {
    result = result.replace('.jpg"', '.jpg' + size + '"').replace('.png"', '.png' + size + '"');
}
console.log(result);

think differently:

var size = "?x-oss-process=image/resize,h_500";
dom.html(str);
$.each('$(dom).find(img)',function(item,i){
    $(item).attr('src',$(item).attr('src')+size);
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b40a53-2b271.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b40a53-2b271.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?