How can I replace image inside a TD with loading image during Ajax call

前端 未结 2 1114
别跟我提以往
别跟我提以往 2021-01-27 05:00

I have an HTML table. In each cell there is an image followed by some text. Something like this:


  This is a test
         


        
2条回答
  •  隐瞒了意图╮
    2021-01-27 05:25

    To change the image is relatively easy:

    $('img[src="image.gif"]').attr('src','path/to/new/image.png');
    

    The selector could be improved if your image had an id ($('#imageIDname'), which would apply only to that one image element) or class ($('.imageClassName') though that would apply to all images of that class-name). I don't know if you want to apply this to all images in all tds or just to one particular img element.

    Coupling that to your ajax call is a little trickier, since I have no idea what your ajax call looks like.

    Also, and this might be just my obsessiveness, your element should look like:

    This is a test
    

    Note the trailing / in the img tag.

提交回复
热议问题