麻煩哪位大神給我看看,到底哪里出錯了?
<!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>
2016-04-20
//定義"改變顏色"的函數s ? function changewh(){ ? ?char.style.width="400px"; ? ?char.style.height="200px";} //定義"改變寬高"的函數 ? function hide() ? ?{ char.style.display="none";} //定義"隱藏內容"的函數 ? function show() ? ? {char.style.display="block";}
這些都沒有定義char
2016-05-20
非常感想!
2016-04-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>
2016-04-20
是你自己太粗心了,你自己看一下changecolor()和changecolor()函數有沒有成對的{}花括號,只有開頭沒有結尾,應該還有其他地方也是粗心導致的,你仔細看看吧,最好重新敲一遍,我也沒工夫找完出來,總之敲代碼很需要細心和耐心
2016-04-20
<div id="char"> ?這里的ID改一下,改成txt