如何使用其他文件中的图像更改背景?

时间:2023-02-09 09:11:26

I am making a website to keep track on my moviecollection. I have a page called "list.php" which lists all my movie titles. Each title is clickable. When you click the movie, an ajax function will retrieve information about the movie from another file called getmovie.php. Then a div expands and the information is being placed inside the expanded div. That was quite easy to make. To make the site more fancy I want to switch the background of list.php to be a poster from the "clicked" movie. The database stores the path to this poster, and getmovie.php will get that. But how can I change the background in list.php to a path being stored in getmovie.php?

我正在建立一个网站来跟踪我的电影收藏。我有一个名为“list.php”的页面,列出了我的所有电影。每个标题都是可点击的。单击该影片时,ajax函数将从另一个名为getmovie.php的文件中检索有关该影片的信息。然后div展开,信息放在扩展的div中。这很容易做到。为了使网站更加花哨,我想将list.php的背景切换为“点击”电影的海报。数据库存储此海报的路径,getmovie.php将获得该路径。但是,如何将list.php中的背景更改为存储在getmovie.php中的路径?

Basicly I have a variable containing a path to an image I want to set as background in another file. How am I supposed to code that?

基本上我有一个变量,包含我想在另一个文件中设置为背景的图像的路径。我该怎么编码呢?

Thank you :)

谢谢 :)

2 个解决方案

#1


0  

I think you could use javascript to change document.body.background when you call the ajax function. For example, in the playMovie() function:

我想你可以在调用ajax函数时使用javascript来更改document.body.background。例如,在playMovie()函数中:

document.body.background = "images/movie01.jpg";

Hope it's useful.

希望它有用。

#2


0  

As I tested with different methods, It is not possible to set a page's background from another page. However you can set the image from the page itself. You should do 2 ajaxs.. First you should get the text with a simple ajax as you have done that already. and Second get the background. write a php script that gets a movie input and displays ONLY the image url in the browser and then do an ajax and set the background of the new page using the retrieved url.

当我使用不同的方法进行测试时,无法从另一个页面设置页面的背景。但是,您可以从页面本身设置图像。你应该做2个ajaxs ..首先你应该用一个简单的ajax来获取文本,就像你已经完成的那样。第二个得到背景。编写一个获取电影输入的php脚本,并在浏览器中仅显示图像URL,然后使用检索到的URL设置ajax并设置新页面的背景。

#1


0  

I think you could use javascript to change document.body.background when you call the ajax function. For example, in the playMovie() function:

我想你可以在调用ajax函数时使用javascript来更改document.body.background。例如,在playMovie()函数中:

document.body.background = "images/movie01.jpg";

Hope it's useful.

希望它有用。

#2


0  

As I tested with different methods, It is not possible to set a page's background from another page. However you can set the image from the page itself. You should do 2 ajaxs.. First you should get the text with a simple ajax as you have done that already. and Second get the background. write a php script that gets a movie input and displays ONLY the image url in the browser and then do an ajax and set the background of the new page using the retrieved url.

当我使用不同的方法进行测试时,无法从另一个页面设置页面的背景。但是,您可以从页面本身设置图像。你应该做2个ajaxs ..首先你应该用一个简单的ajax来获取文本,就像你已经完成的那样。第二个得到背景。编写一个获取电影输入的php脚本,并在浏览器中仅显示图像URL,然后使用检索到的URL设置ajax并设置新页面的背景。