jQuery to prepend URL in img src attribute

后端 未结 3 1801
有刺的猬
有刺的猬 2021-01-06 10:54

I just need a jQuery snippet to do the prepend in img src , i.e


The code snippet jQuery is to prepe

3条回答
  •  失恋的感觉
    2021-01-06 11:39

    This should work:

    $.ready(function() {
        $('img').each(function() {
            $(this).attr('src', cdn + $(this).attr('src'));
        });
    });
    

    However I'm not sure it is the good solution for using a CDN, as the browser will have already tried to load the images from your server at the time the script will be called.

    You should do this on the server side instead.

提交回复
热议问题