幫忙看下我的代碼,為什么都沒有反應
<!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="改變顏色" > ?
? ? <input type="button" value="改變寬高" >
? ? <input type="button" value="隱藏內容" >
? ? <input type="button" value="顯示內容" >
? ? <input type="button" value="取消設置" >
? </form>
? <script type="text/javascript">
? text=document.getElementById("txt");
? buttons=document.getElementsByTagName("input");
//定義"改變顏色"的函數(shù)
? buttons[0].onclick=function(){
? ? ? text.style.color="red";
? ? ? text.style.backgroundColor="grey";
? }?
//定義"改變寬高"的函數(shù)
buttons[1].onclick=function(){
? ? ? text.style.width="100px";
? ? ? text.style.height="200px";
? }?
//定義"隱藏內容"的函數(shù)
buttons[2].onclick=function(){
? ? ? text.style.display="none";
? }?
//定義"顯示內容"的函數(shù)
buttons[3].onclick=function(){
? ? ? text.style.display="block";
?}?
//定義"取消設置"的函數(shù)
buttons[4].onclick=function(){
? ? ? r=confirm("確認取消上面的所有設置嗎");
? ? ? if(r){
? ? ? ? text.removeAttribute('style');
? ? ? }
? }?
? </script>
</body>
</html>
2016-03-25
??? <input type="button" value="改變顏色" onclick="a()"/> ?
??? <input type="button" value="改變寬高" onclick="b()">
??? <input type="button" value="隱藏內容" onclick="c()">
??? <input type="button" value="顯示內容" onclick="d()">
??? <input type="button" value="取消設置" onclick="e()">
? </form>
? <script type="text/javascript">
?? function a(){
?????? var mychar = document.getElementById("con");
?????? mychar.style.color="red";
?? }
?? function b(){
?????? var char = document.getElementById("txt");
?????? char.style.width="400px";
?????? char.style.height="180px";
?? }
? function c(){
????? var add = document.getElementById("txt");
????? add.style.display="none";
? }
? function d(){
????? var add = document.getElementById("txt");
????? add.style.display="block";
? }
? function e(){
????? var em =confirm("你確定要取消嗎?");
????? if(em==true)
????? {
????? txt.removeAttribute('style');
????? }
? }
2016-03-04
首先,你給style賦值的時候,沒有將值加引號,
其次,text.style..display用了兩個點,
?r=confirm("確認取消上面的所有設置嗎");這里的;你用的是中文的;,要用英文的;
最后,你的?text.removeAttributes('style');這句根本就不會重置,
請把removeAttributes的s去掉,不過style的值是多少,都不要加s
2016-03-04
求大神解答
2016-03-03
沒給按鈕添加事件:onclick="自定義";還有if那里沒有給判斷,如:if(r==true)
2016-03-03
button沒添加事件
2016-03-03
你應該到body段落的html代碼段里去調用方程,而且button[x]這樣不管用吧(我不清楚)?
給你看一段我的
<input type="button" value="改變顏色" onClick="changeColor()";> ?
? ? <input type="button" value="改變寬高" onClick="changeSize()";>
? ? <input type="button" value="隱藏內容" onClick="hidecontext()";>
? ? <input type="button" value="顯示內容" onClick="showContext()";>
? ? <input type="button" value="取消設置" onClick="resetSetting()";>
? </form>
? <script type="text/javascript">
? ? var mydiv = document.getElementById("txt");?
//定義"改變顏色"的函數(shù)
function changeColor(){
? ? mydiv.style.color="#db7093";
? ? mydiv.style.backgroundColor="#6495ED";
}
//定義"改變寬高"的函數(shù)
function changeSize(){
? ? mydiv.style.width="100px";
? ? mydiv.style.height="300px";
}
?
這樣就可以了。
2016-03-03
?buttons數(shù)組可能不太適用,你換一種吧。