如何动态更改html背景 [英] how to change html background dynamically

查看:297
本文介绍了如何动态更改html背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  body 
{
background:#000000 url(images / back_all.gif)repeat-x top;
字体:12px Tahoma,Arial,Helvetica,sans-serif;
颜色:#666666;
}

我有一个javascript,它会在window.onload之后加载并导致页面要扩大正面意义,所以我的其余部分将变黑。
如何在JavaScript代码完成后再次将背景图片应用于我的页面?

解决方案

jQuery:



$('body')。css('backgroundImage','url(something.gif)');






非jQuery:



分配正文ID:< body id =the_body>



document.getElementById('the_body')。style.backgroundImage =something.gif



或as John提到



document.body.style.backgroundImage =something.gif;



此外,T POPs提到,确保它在最后:

 < ; HTML> 
< body>
.....数据........
< script type =text / javascript>
....代码........
< / script>
< / body>
< / html>


I have a page which has a style like this in a css file:

body
{
    background: #000000 url(images/back_all.gif) repeat-x top;
    font: 12px Tahoma, Arial, Helvetica, sans-serif;
    color: #666666;
}

and I have either a javascript which is loaded after window.onload and causes page to be expand vericaly and so the rest of my page will become black. how can I apply the background image to my page again after the javascript code is completed?

解决方案

jQuery:

$('body').css('backgroundImage', 'url(something.gif)');


Non-jQuery:

Assign Body an ID: <body id="the_body">

document.getElementById('the_body').style.backgroundImage = "something.gif"

or as John mentioned

document.body.style.backgroundImage = "something.gif";

and furthermore, a T POPs Mentioned, make sure it goes at the end:

<html>
<body>
..... Data ........
<script type="text/javascript">
.... Code ........
</script>
</body>
</html>

这篇关于如何动态更改html背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆