求在js中更换文件的css样式

html-css017

求在js中更换文件的css样式,第1张

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns=" http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<title>无标题文档</title>

<style type="text/css">

.css1{ cursor:pointer}

.cs{width:500pxheight:30pxline-height:30pxbackground:#e3e3e3font-size:12pxcursor:pointer}

.ll{width:100pxheight:300pxbackground:#993300color:#FFFfont-size:12pxfont-weight:boldpadding:10px}

</style>

</head>

<body>

<div id="sty">

<div class="css1">样式(点击我)</div>

<div class="cs">要更改的目标</div>

</div>

</body>

</html>

<script type="text/javascript">

var objs=document.getElementById("sty").getElementsByTagName("div")

objs[0].onclick=function(){

objs[1].className="ll"

}

</script>

你是不是想可以修改的js??

<script src="demo.jsp"></script>

<script src="demo.asp"></script>

<script src="demo.aspx"></script>

<script src="demo.php"></script>

相应的文件里面用相应代码处理就可以

里面的格式

respose 输出 和js 文件里面的格式一样就可以

不生效 就为空就可以了!

<script src="demo.jsp?参数=值"></script>

可以用参数的形式做处理

静态的页面话就没办法修改了

只能 直接修改js文件

补充: 可以啊!!给<span id="spa"><script src="a.js"></script></span>

//外面加个span

<script>

document.all.spa.innerHTML=""

</script>

更改一个标签的 class 属性的代码是:

document.getElementById( id ).className = 字符串

document.getElementById( id ) 用于获取标签对应的 DOM 对象,你也可以用其它方法获取。className 是 DOM 对象的一个属性,它对应于标签的 class 属性。字符串 是 class 属性的新值,它应该是一个已定义的CSS选择符。

class 属性是在标签上引用样式表的方法之一,它的值是一个样式表的选择符,如果改变了 class 属性的值,标签所引用的样式表也就更换了,所以这属于第一种修改方法。

利用这种办法可以把标签的CSS样式表替换成另外一个,也可以让一个没有应用CSS样式的标签应用指定的样式。

举例:

代码如下:

<style type="text/css">

.txt {

font-size: 30pxfont-weight: boldcolor: red

}

</style>

<div id="tt">欢迎光临!</div>

<p><button on click="setClass()">更改样式</button></p>

<script type="text/javas cript">

function setClass()

{

document.getElementById( "tt" ).className = "txt"

}

</script>