怎么都運行不了,找不出錯誤了。
<!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;}
#txt{
? ? 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="txt">?
? ? ?<h5>JavaScript為網(wǎng)頁添加動態(tài)效果并實現(xiàn)與用戶交互的功能。</h5>
? ? ? ? <p>1. JavaScript入門篇,讓不懂JS的你,快速了解JS。</p>
? ? ? ? <p>2. JavaScript進階篇,讓你掌握JS的基礎語法、函數(shù)、數(shù)組、事件、內(nèi)置對象、BOM瀏覽器、DOM操作。</p>
? ? ? ? <p>3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
? </div>
? <form>
? <!--當點擊相應按鈕,執(zhí)行相應操作,為按鈕添加相應事件-->
? ? <input type="button" onclick="changecolor()" value="改變顏色" > ?
? ? <input type="button" onclick="changewh()" value="改變寬高" >
? ? <input type="button" onclick="hidetext()" value="隱藏內(nèi)容" >
? ? <input type="button" onclick="showtext()" value="顯示內(nèi)容" >
? ? <input type="button" onclick="cancelset()" value="取消設置" >
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
? ? var mystr=document.getElementById("txt");
? ?function changecolor()
? ?{
? ? ? ?mystr.style.color="red";
? ? ? ?mystr.backgroundColor="#CCC";
? ?}
//定義"改變寬高"的函數(shù)
? ?function changewh()
? ?{
? ? ? ?mystr.style.width="300";
? ? ? ?mystr.style.height="600";
? ?}
//定義"隱藏內(nèi)容"的函數(shù)
? ?function hidetext()
? ? ? { mystr.style.display="none";}
//定義"顯示內(nèi)容"的函數(shù)
? ?function showtext()
? ? ?{
? ? ? ? mystr.style.display="block";
? ? ?}
//定義"取消設置"的函數(shù)
? ?function cancelset()
? ?{ var message=confirm("確定要重置嗎?")
? ? ? ?if(message==true)
? ? ? ?mystr.style="none";}
? ?}
? </script>
</body>
</html>
2018-08-01
你沒有定義你的變量mystr,你用var定義一下試試
2018-07-26
<!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;}
#txt{
??? 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="txt">
???? <h5>JavaScript為網(wǎng)頁添加動態(tài)效果并實現(xiàn)與用戶交互的功能。</h5>
??????? <p>1. JavaScript入門篇,讓不懂JS的你,快速了解JS。</p>
??????? <p>2. JavaScript進階篇,讓你掌握JS的基礎語法、函數(shù)、數(shù)組、事件、內(nèi)置對象、BOM瀏覽器、DOM操作。</p>
??????? <p>3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
? </div>
? <form>
? <!--當點擊相應按鈕,執(zhí)行相應操作,為按鈕添加相應事件-->
??? <input type="button" onclick="color()" value="改變顏色" >?
??? <input type="button" onclick="width1()" value="改變寬高" >
??? <input type="button" onclick="d3()" value="隱藏內(nèi)容" >
??? <input type="button" onclick="d4()" value="顯示內(nèi)容" >
??? <input type="button" onclick="d5()" value="取消設置" >
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
??? var con=document.getElementById("con");
??? var txt=document.getElementById("txt");
??? function color(){
???????
??????? con.style.color="red";
??????? txt.style.color="blue";
??????? con.style.backgroundColor="black";
??????? txt.style.backgroundColor="#ccc";
??? }
//定義"改變寬高"的函數(shù)
??? function width1(){
??????? con.style.width="1000px";
??????? con.style.height="20px";
??????? txt.style.width="100px";
??????? txt.style.height="200px";
??? }
//定義"隱藏內(nèi)容"的函數(shù)
??? function d3(){
??????? txt.style.display="none";
??? }
//定義"顯示內(nèi)容"的函數(shù)
??? function d4(){
??????? txt.style.display="block";
??? }
//定義"取消設置"的函數(shù)
??? function d5(){
??????? var a=confirm("確認取消變動嗎?");
??????? if(a==true){
??????????? var s=document.getElementById("txt");
??????????? s.removeAttribute("style");
??????? }
??? }
? </script>
</body>
</html>
2018-07-26
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="gb2312">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h2 id="con">javascript</h2>
<div id="txt">
<h5>JavaScript為網(wǎng)頁添加動態(tài)效果并實現(xiàn)與用戶交互的功能。</h5>
<p>1. JavaScript入門篇,讓不懂JS的你,快速了解JS。</p>
<p>2. JavaScript進階篇,讓你掌握JS的基礎語法、函數(shù)、數(shù)組、事件、內(nèi)置對象、BOM瀏覽器、DOM操作。</p>
<p>3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
</div>
<style>
#txt{height: 150px;background: #424242;color:aliceblue;}
</style>
<form>
<input type="button" value="改變顏色" onclick="ocolor()">
<input type="button" value="改變寬高" onclick="owidth()">
<input type="button" value="隱藏內(nèi)容" onclick="off()">
<input type="button" value="顯示內(nèi)容" onclick="off()">
<input type="button" value="取消設置" onclick="not()">
</form>
<script type="text/javascript">
var otxt = document.getElementById('txt');
var ocon = document.getElementById('con');
function ocolor(){
otxt.style.background = 'Orchid';
}
function owidth(){
otxt.style.width = '300px';
otxt.style.height = 'auto';
}
function off(){
if(otxt.style.display=='block'){
otxt.style.display='none';
}else{
otxt.style.display='block' ;
}
}
function not(){
otxt.style='';
}
</script>
</body>
</html>
<!-- //定義"改變顏色"的函數(shù)
//定義"改變寬高"的函數(shù)
//定義"隱藏內(nèi)容"的函數(shù)
//定義"顯示內(nèi)容"的函數(shù)
//定義"取消設置"的函數(shù) -->
2018-07-26
后面弄著弄著效果出來了,可是那個改變寬高怎么都實現(xiàn)不了