亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

麻煩哪位大神給我看看,到底哪里出錯了?

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />

<title>javascript</title>

<style type="text/css">

body{font-size:12px;}

#char{

? ? height:400px;

? ? width:600px;

border:#333 solid 1px;

padding:5px;}

p{

line-height:18px;

text-indent:2em;}

</style>

</head>

<body>

? <h2 id="con">JavaScript課程</H2>

? <div id="char">?

? ? ?<h5>JavaScript為網頁添加動態效果并實現與用戶交互的功能。</h5>

? ? ? ? <p>1. JavaScript入門篇,讓不懂JS的你,快速了解JS。</p>

? ? ? ? <p>2. JavaScript進階篇,讓你掌握JS的基礎語法、函數、數組、事件、內置對象、BOM瀏覽器、DOM操作。</p>

? ? ? ? <p>3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>

? </div>

? <form>

? <!--當點擊相應按鈕,執行相應操作,為按鈕添加相應事件-->

? ? <input type="button" value="改變顏色" onclick="changecolor()"> ?

? ? <input type="button" value="改變寬高" onclick="changewh()">

? ? <input type="button" value="隱藏內容" onclick="hide()">

? ? <input type="button" value="顯示內容" onclick="show()">

? ? <input type="button" value="取消設置" onclick="cal()">

? </form>

? <script type="text/javascript">

? var char=document.getElementById("txt");

? ?function changecolor(){

? ?char.style.color="red";

? ?char.style.backgroundColor="#ccc";

//定義"改變顏色"的函數s

? function changewh(){

? ?char.style.width="400px";

? ?char.style.height="200px";}

//定義"改變寬高"的函數

? function hide()

? ?{ char.style.display="none";}

//定義"隱藏內容"的函數

? function show()

? ? {char.style.display="block";}

//定義"顯示內容"的函數

? function cal(){

? ? var par=confirm("是否取消設置?");

? ? ? if(par==true){

? ? ? char.removeAttribute("style");

? ? ? ? ?}

? ? ?

//定義"取消設置"的函數

??


? </script>

</body>

</html>


正在回答

5 回答

//定義"改變顏色"的函數s ? function changewh(){ ? ?char.style.width="400px"; ? ?char.style.height="200px";} //定義"改變寬高"的函數 ? function hide() ? ?{ char.style.display="none";} //定義"隱藏內容"的函數 ? function show() ? ? {char.style.display="block";}


這些都沒有定義char

0 回復 有任何疑惑可以回復我~
#1

uyisi

在<script type="text/javascript">后一行就有定義char的
2016-04-20 回復 有任何疑惑可以回復我~

非常感想!

0 回復 有任何疑惑可以回復我~
#1

慕粉3206535 提問者

打錯了,是感謝
2016-05-20 回復 有任何疑惑可以回復我~

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" Content="text/html; charset=utf-8" />

<title>javascript</title>

<style type="text/css">

body{font-size:12px;}

#char{

? ? height:400px;

? ? width:600px;

border:#333 solid 1px;

padding:5px;}

p{

line-height:18px;

text-indent:2em;}

</style>

</head>

<body>

? <h2 id="con">JavaScript課程</H2>

? <div id="char">?

? ? ?<h5>JavaScript為網頁添加動態效果并實現與用戶交互的功能。</h5>

? ? ? ? <p>1. JavaScript入門篇,讓不懂JS的你,快速了解JS。</p>

? ? ? ? <p>2. JavaScript進階篇,讓你掌握JS的基礎語法、函數、數組、事件、內置對象、BOM瀏覽器、DOM操作。</p>

? ? ? ? <p>3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>

? </div>

? <form>

? <!--當點擊相應按鈕,執行相應操作,為按鈕添加相應事件-->

? ? <input type="button" value="改變顏色" onclick="set.changecolor()"> ?

? ? <input type="button" value="改變寬高" onclick="set.changewh()">

? ? <input type="button" value="隱藏內容" onclick="set.hide()">

? ? <input type="button" value="顯示內容" onclick="set.show()">

? ? <input type="button" value="取消設置" onclick="set.cal()">

? </form>

? <script type="text/javascript">

? var char=document.getElementById("char");

? ?var set={

changecolor:function(){

? ?char.style.color="red";

? ?char.style.backgroundColor="#ccc"},

changewh:function(){

? ?char.style.width="400px"

? ?char.style.height="200px"},

hide:function(){?

? ?char.style.display="none"},

show:function(){

? ?char.style.display="block"},

cal:function(){

var message=confirm("你確定要重置?")

if(message==ture)

{char.removeAttribute('style')}

}

? ?}

? </script>

</body>

</html>


0 回復 有任何疑惑可以回復我~

是你自己太粗心了,你自己看一下changecolor()和changecolor()函數有沒有成對的{}花括號,只有開頭沒有結尾,應該還有其他地方也是粗心導致的,你仔細看看吧,最好重新敲一遍,我也沒工夫找完出來,總之敲代碼很需要細心和耐心

0 回復 有任何疑惑可以回復我~
#1

uyisi

對了再加上樓上那位兄弟的回答就沒錯誤了。沒發現 <div id="char"> 這里的ID改一下,改成txt
2016-04-20 回復 有任何疑惑可以回復我~

<div id="char"> ?這里的ID改一下,改成txt

1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

麻煩哪位大神給我看看,到底哪里出錯了?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號