<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
<title>className屬性</title>
<style>
????body{?font-size:16px;}
????.one{
????????border:1px?solid?#eee;
????????width:230px;
????????height:50px;
????????background:#ccc;
????????color:red;
????}
????.two{
????????border:1px?solid?#ccc;
????????width:230px;
????????height:50px;
????????background:#9CF;
????????color:blue;
????}
????</style>
</head>
<body>
????<p?id="p1"?>?JavaScript使網(wǎng)頁(yè)顯示動(dòng)態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</p>
????<input?type="button"?value="添加樣式"?onclick="add()"/>
????<p?id="p2"?class="one">JavaScript使網(wǎng)頁(yè)顯示動(dòng)態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</p>
????<input?type="button"?value="更改外觀"?onclick="modify()"/>
????<input?type="button"?value="清除樣式"?onclick="clean()"/>
????<script?type="text/javascript">
???????function?add(){
??????????var?p1?=?document.getElementById("p1");
??????????p1.className?=?"one";
???????}
???????function?modify(){
??????????var?p2?=?document.getElementById("p2");
??????????p2.className?=?"two";
???????}
???????function?clean(){
?????????var?deletestyle?=?confirm('是否清除樣式')
?????????if(deletestyle?==?true){
?????????????document.getElementById("p2").removeAttribute("style");
?????????}
????????else{
????????????alert("啥都不做");
????????}
???????}
????</script>
</body>
</html>
2016-01-23
removeAttribute()方法用來刪除指定的屬性,是.style的,在<style></style>標(biāo)簽里面改的樣式好像重置不了
不知道是不是這樣
2022-03-29
可以去做產(chǎn)品啊~~
msaotbqtpjfyaqcooaqtwsrefavymzqqslfwxjtrjxdticnldqwvqkuiqkbhchsxeosxrvqqlogxcsqvbdhvwecihgdzopegwyhrnnkhfhqnrmxigeubexuoobboyno
2016-04-27
樓主我知道了 ,在<style></style>標(biāo)簽里面改的樣式是清除不了的,可是你知道怎么改嗎
2016-04-27
請(qǐng)問樓主這個(gè)問題如何解決啊,我也是有這個(gè)困擾
2016-01-23
也許是因?yàn)椤?。?strong>removeAttribute("style"),style的值沒有寫在P1和P2標(biāo)簽里面。是寫在head上面的。所以。我覺得可以這樣寫
function clean(){
? ? ? ? ?var deletestyle = confirm('是否清除樣式')
? ? ? ? ?if(deletestyle == true)
? ? ? ? ?{
? ? ? ? ? ? ?p1.className = "";
? ? ? ? ? ? ?p2.className = "one";
? ? ? ? ?}
? ? ? ? else{
? ? ? ? ? ? alert("啥都不做");
? ? ? ? }