This article mainly introduces jquery's method of dynamically changing the webpage background image. If you need it, you can refer to the following: Sometimes, we can provide users with very considerate functions, for example, you can determine when a user accesses the website and give a greeting, such as Good evening or good afternoon. In addition, you can change the background color of the webpage. For example, you can use the background of a star in the sky at night, the sun is shining during the day, or the background of the topic is used for a specific holiday, it makes your website very flexible and not boring.
The following describes how to implement background replacement:
How to Implement
The JQuery code is as follows:
The Code is as follows:
Function doChangeBkg ()
{
Var bkgUrl = $ ("# inputBkgUrl"). val ();
Var repeateMode = $ ("# inputRepeatMode"). val ();
Var s ="";
$ ("# OutputDiv" ).html (s );
}
Native JavaScript code:
The Code is as follows:
Function doChangeBkg ()
{
Var bkgUrl = $ ("# inputBkgUrl"). val ();
Var repeateMode = $ ("# inputRepeatMode"). val ();
Var s ="";
$ ("# OutputDiv" ).html (s );
}
Front-end code:
The Code is as follows:
Background image URL:
Duplicate background image:RepeatNo-repeatRepeat-xRepeat-y