To set the src attribute of an image using jQuery, you can use the attr() method. Here's an example:

// Select the image element
var myImg = $('#my-image');

// Set the src attribute
myImg.attr('src', 'path/to/image.jpg');

In this example, we're selecting the image element using its id attribute (#my-image). Then, we're setting the src attribute to the path of our image file.

You can also chain the attr() method with other jQuery methods. For example, you could fade in the image after it's loaded:

var myImg = $('#my-image');
myImg.attr('src', 'path/to/image.jpg').hide().fadeIn();

In this example, we're chaining the attr() method with the hide() and fadeIn() methods to fade in the image after it's loaded.

set img src by jquery

原文地址: https://www.cveoy.top/t/topic/bEhX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录