第二個重置按鈕怎么設(shè)置?按照我的代碼,第二重置沒反應(yīng)的
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>引用JS文件</title>
<style type="text/css">
div.sj{border: 1px solid #000;padding: 10px;width:400px;height:100px;
}
?.one{
? ? ?boder:1px solid red;
? ? ?width:200px;
? ? ?height=150px;
? ? ?backgroundColor=#ccc;
? ? ?color:blue;
?}
</style>
</head>
<body>
?<p id="p1">
? ? ?什么是變量? 從字面上看,變量是可變的量;
?</p>
?<form>
? ? ?<input type="button" value="添加樣式" onclick="add() "/>
? ? ?<input type="button" value="重置" onclick="reve()"/>
? ? ?
?</form><br>
?<div class="sj">
? ? ?
?<p id="p2">
? ? ?我們可以把變量看做一個盒子,盒子用來存放物品,物品可以是衣服、玩具、水果...等。
?</p>
?
?</form></div><br>
?<form>
? ? ?<input type="button" value="改變顏色" onclick="changecolor() "/>
? ? ?<input type="button" value="重置" ?onclick="rev()"/>
? ? ?</form>
<script type/javascript>
? ? function add(){
? ? ? ? var p1=document.getElementById("p1")
? ? ? ? p1.style.color="red";
? ? ? ? p1.style.backgroundColor="#ccc";
? ? }
? ? function reve(){
? ? ? ? var p1=document.getElementById("p1")
? ? ? ? p1.removeAttribute('style');
? ? }
? ? function changecolor(){
? ? ? ? var p2=document.getElementById("p2");
? ? ? ? p2.className="one";
? ? }
? ?function rev(){
? ? ? ?var p2=doucument.getElementById("p2");
? ? ? ?p2.removeAttribute('style');
? ?}
</script>
---------------------------------
用 <input type="reset" value="重置";/>也是沒反應(yīng)呢、
第二個重置按鈕怎么設(shè)置有效?
2016-04-05
第54行?var p2=doucument.getElementById("p2");
document拼寫錯誤~
2018-06-21
boder應(yīng)該是border;
height=應(yīng)該是height:150px;
backgroundColor正確寫法應(yīng)該是background-color,寫在一起的是Object改變樣式寫在一起的,css樣式背景色要分開寫;
?var p2=doucument.getElementById("p2");正確拼寫應(yīng)該是document;
p2.removeAttribute('style');應(yīng)該寫成p2.className="style";
2016-07-31
關(guān)于第二個重置沒有作用,和我犯了一樣的錯誤,轉(zhuǎn)答案“
mychar.removeAttribute("style");//這里移除的style是節(jié)點里面聲明的style,而不能移除className所帶來的css樣式,假如<p id="con" style=“color:red;”>JS進階篇</p> 那么按了重置,red就會沒有。
修改:
mychar.removeAttribute("class");
”
2016-05-06
你的代碼 錯誤的地方好多,都是些單詞拼錯了。比如說.one樣式里面的 border ?還有background-color。Java script里面調(diào)用屬性的拼寫方式和css里面是不一樣的,注意哦
2016-05-03
document.拼錯
2016-04-05
document.拼錯
2016-04-05
p2.className='';
2016-04-05
function rev(){
? ? ? ?var p2=doucument.getElementById("p2");
? ? ? ?p2.removeAttribute('style');
? ?}
這個doucment寫錯單詞啦
2016-04-05