小问题 急 50分在线等 JavaScript style.cssText问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 04:04:46
1、先定义一个CSS规则,然后this.className=''
2、document.getElementById("a").style.cssText="border-collapse:collapse;border-spacing:1;border:1 solid #0B2565;background-color:white;color:black;"
不知道“先定义一个CSS规则,然后this.className=''”是什么意思
最后能把他补全来
越说越糊涂了 是不是要在程序里面加个什么东东的啊

你好:

提示:把代码保存为a.htm即可预览效果
1、先定义一个CSS规则,然后this.className=''
代码中.style1 就是CSS规则
<script>
function setDivBG(s)
{
document.getElementById("div1").className=s;//这就是this.className=''
}
</script>

2、document.getElementById("a").style.cssText就是直接付给他CSS样式省去了定义CSS的步骤

你这两条是动态变换CSS的方法吧?

<script>
function setDivBG(s)
{
document.getElementById("div1").className=s;
}
</script>
<head>
<style type="text/css">
.style1
{

width: 100px;
height: 100px;
background-image:url('https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif');
}
.style2
{

width: 100px;
height: 100px; <