為什么按鈕點擊都沒有效果???以下是我的代碼。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<style type="text/css">
body{font-size:12px;}
#txt{
? ? height:400px;
? ? width:600px;
border:red solid 1px;
padding:5px;}
p{
line-height:18px;
text-indent:2em;}
</style>
</head>
<body>
? ?<script type="text/javascript">
//定義"取消設置"的函數
function init4(){
? ? var stu = documnet.getElementById("con");
? ? stu = confirm("確定設置");
? ? if(stu == true){
? ? document.write("確定設置,很好!"); ? ?
? ? }
? ? else{
? ? ? ? document.write("null");
? ? }
}
//定義"改變顏色"的函數
function init(){
? ? var one1 = document.getElementById("one");
? ? one1.style.color = "blue";
? ? one1.style.backgroundColor = "#CCC";
}//定義"改變寬高"的函數
function init1(){
? ? var two1 = document.getElementById("two");
? ? two1.style.width = "200px";
? ? two1.style.height = "100px";
}
//定義"隱藏內容"的函數
function init2(){
? ? var three1 = document.getElementById("three");
? ? three1.style.display = "none";
}
//定義"顯示內容"的函數
function init3(){
? ? var four1 = document.getElementById("four");
? ? four1.style.display = "block";
}
? </script>
?<h1 id="con">JavaScript課程</h1>
? <div id="txt">?
? ? ?<h2 id="one">JavaScript為網頁添加動態效果并實現與用戶交互的功能。</h2>
? ? ? ? <p id="two">1. JavaScript入門篇,讓不懂JS的你,快速了解JS。</p>
? ? ? ? <p id="three">2. JavaScript進階篇,讓你掌握JS的基礎語法、函數、數組、事件、內置對象 、BOM瀏覽 器、DOM操作。</p>
? ? ? ? <p id="four">3. 學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
? </div>
? ?<form>
? <!--當點擊相應按鈕,執行相應操作,為按鈕添加相應事件-->
? ? <input type="button" value="改變顏色" onclick="init"> ?
? ? <input type="button" value="改變寬高" onclick="init1">
? ? <input type="button" value="隱藏內容" onclick="init2">
? ? <input type="button" value="顯示內容" onclick="init3">
? ? <input type="button" value="取消設置" onclick="init4">
? </form>
</body>
</html>
2019-01-05
一、改為onclick="init()",onclick="init1()",onclick="init2()",onclick="init3()",onclick="init4()"
二、函數init3()(顯示內容的方法),你針對id=four的p標簽進行操作,但是它本來就是顯示的,你可以改為
????????????????????var four1 = document.getElementById("three");
????????在對id為three的p標簽進行隱藏后在使用這個按鈕就可以顯示內容了
三、函數init4()看不懂,不知道你想怎么操作
2019-01-05
你的input標簽里面的 onclick 屬性 少寫括號“()”你再改了試試
另外不知道是不是你故意這么寫的,但是你現在的代碼邏輯并不能實現正確的功能,建議再檢查檢查。
祝你寫代碼開心~