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

What to do if jquery does not display the image background

藏色散人
Release: 2023-02-07 10:26:28
Original
1728 people have browsed it

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+')')
Copy after login

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")
})
});
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template