為什么我的按鈕全部都沒有用啊,求大神幫忙看看
<!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ù)組、事件、內置對象、BOM瀏覽器、DOM操作。</p>
??????? <p>3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
? </div>
? <form>
? <!--當點擊相應按鈕,執(zhí)行相應操作,為按鈕添加相應事件-->
??? <input type="button" value="改變顏色" onClick=changeys() > ?
??? <input type="button" value="改變寬高" onClick=changekg()>
??? <input type="button" value="隱藏內容" onClick=changenr()>
??? <input type="button" value="顯示內容" onClick=changexs()>
??? <input type="button" value="取消設置" onClick=changeqx()>
? </form>
? <script type="text/javascript">
? var mytxt=document.getElementById("txt");
//定義"改變顏色"的函數(shù)
function changeys(){
???? var mytxt=document.getElementById("txt");
??? mytxt.style.color="red";
??? mytxt.style.backgroundColor="blue";
}
//定義"改變寬高"的函數(shù)
function changekg(){
??? mytxt.style.width="100px";
??? mytxt.style.height="200px";
}
//定義"隱藏內容"的函數(shù)
function changenr(){
??? mytxt.display="none";
}
//定義"顯示內容"的函數(shù)
function changexs(){
??? mytxt.display="block";
}
//定義"取消設置"的函數(shù)
function changeqx(){
??? var re=confirm("是否取消設置");
??? if(re==true)
??? {
????? re.style="none";
??? }
}
? </script>
</body>
</html>
2018-12-13
onclick="方法名()",需要雙引號;看著樓主方法命名不規(guī)范很難受.顏色改變顏色叫changeColor,隱藏叫hide,顯示叫show,取消叫cancel...
2018-12-11
<input type="button" value="改變顏色" onClick=changeys() /> ?
??? <input type="button" value="改變寬高" onClick=changekg()/>
??? <input type="button" value="隱藏內容" onClick=changenr()/>
??? <input type="button" value="顯示內容" onClick=changexs()/>
??? <input type="button" value="取消設置" onClick=changeqx()/>
這里格式不完整,少了/
2018-12-10
<!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ù)組、事件、內置對象、BOM瀏覽器、DOM操作。</p>
? ? ? ? <p>3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
? </div>
? <form>
? <!--當點擊相應按鈕,執(zhí)行相應操作,為按鈕添加相應事件-->
? ? <input type="button" value="改變顏色" onclick="newColor ()">??
? ? <input type="button" value="改變寬高" onclick="newWandH ()">
? ? <input type="button" value="隱藏內容" onclick="newDisplay ()">
? ? <input type="button" value="顯示內容" onclick="newBlock ()">
? ? <input type="button" value="取消設置" onclick="newSetting ()">
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
function newColor (){
var changeColor = confirm("是否修改顏色");
if (changeColor == true){
var h2Color = document.getElementById("con");
h2Color.style.color = "skyblue";
}
}
//定義"改變寬高"的函數(shù)
function newWandH (){
var changeWandH = confirm("是否修改正文寬高");
if (changeWandH == true){
var txtWandH = document.getElementById("txt");
txtWandH.style.width = "800px";
txtWandH.style.height = "800px";
}
}
//定義"隱藏內容"的函數(shù)
function newDisplay (){
var changeDisplay = confirm("是否隱藏內容");
if (changeDisplay == true){
var pDisplay = document.getElementById("txt");
? ? pDisplay.style.display="none";
}
}
//定義"顯示內容"的函數(shù)
function newBlock (){
var changeBlock = confirm("是否顯示內容");
if (changeBlock == true){
var txtBlock = document.getElementById("txt");
txtBlock.style.display = "block";
}
}
//定義"取消設置"的函數(shù)
function newSetting (){
var changeSetting = confirm("是否修改顏色");
if (changeSetting == true){
var qSetting = document.getElementById("con");
qSetting.style.color = "black";
var rSetting = document.getElementById("txt");
rSetting.style.width = "600px"
rSetting.style.height = "400px"
rSetting.style.display = "block"
}
}
? </script>
</body>
</html>
2018-12-10
上面哪位仁兄說的雙引號也記得加上...
2018-12-10
根據(jù)老夫30多年代碼觀寫經(jīng)驗,隨便一瞟4處問題。
導致按鈕不生效的是var re=confirm("是否取消設置");這一行的最后一個中文符號
隱藏內容與顯示內容里面mytxt.display="none"與? mytxt.display="block";都要把style加上
取消設置里面re這個變量是用來表示彈框的。你改變它的style干嘛?換成mytxt這個才是你要改變的
改變顏色的函數(shù)里面就不要再取id了,你外層寫了一個取id的全局變量。。盡量不要出現(xiàn)重復代碼
2018-12-10
onClick="changeys()"? ?加上雙引號