Home  >  Article  >  Web Front-end  >  What to do if jquery does not display the image background

What to do if jquery does not display the image background

藏色散人
藏色散人Original
2023-02-07 10:26:281708browse

jquery does not display the image background because the path is incorrect. The solution: 1. Open the corresponding js file; 2. Pass "let src='clock/img/afternoon.png';them_icons.css( 'background','url(' src ')')" method can be used to reset the background image.

What to do if jquery does not display the image background

The operating environment of this tutorial: Windows 10 system, jquery version 3.2.1, DELL G3 computer

What should I do if jquery does not display the image background? ?

The solution in jquery is to set the image not to be displayed

The solution to the setting background image in jquery is not to be displayed

let src='clock/img/afternoon.png';
them_icons.css('background','url('+src+')')

The main problem lies in the path, the relative path is relative to the html file With the path of the image, not the path of the js file relative to the image.

Related knowledge expansion:

jq realizes changing pictures by clicking the button

What to do if jquery does not display the image background

##Attached jq code:

$(function(){
$("#btn1").click(function(){
$("img").attr("src","img/01.jpg")
})
$("#btn2").click(function(){
$("img").attr("src","img/02.jpg")
})
$("#btn3").click(function(){
$("img").attr("src","img/03.jpg")
})
});

Recommended Study: "

jQuery Video Tutorial"

The above is the detailed content of What to do if jquery does not display the image background. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn