課程
/前端開發
/JavaScript
/JavaScript入門篇
為啥加上改變寬高的函數之后,點擊任何按鈕都不起作用?
2017-08-29
源自:JavaScript入門篇 4-1
正在回答
<!DOCTYPE html>
<html>
? <head>
? ? <title>javascript</title>
<style type="text/css">
body{
font-size:15px;
}
#txt{
height:400px;
width:600;
border:#333 solid 1px;
padding:5px;
p{
line-height:18px;
text-indent:2em;
</style>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
? ? ?</head>
??
? <body>
? ? <h2 id="con">JavaScript課程</h2>
? ? <div id="txt">
? ? <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="hidetxt()"/>
? ? <input type="button" value="顯示內容" onclick="showtxt()"/>
? ? <input type="button" value="取消設置" onclick="cs()"/>
? ? ? </form>
? ? ? <script type="text/javascript">
? ? var mychar=document.getElementById("txt");
? ? function changecolor(){
? ? ?mychar.style.color="red";
? ? }
? ? function changewh(){
? ? mychar.style.width="800px";
? ? mychar.style.height="200px";
? ? function hidetxt(){
? ? ?mychar.style.display="none";
? ??
? ? function showtxt(){
? ? ?mychar.style.display="block";
? ? function cs(){
? ? var flag=confirm("取消設置?");
? ? if(flag==true){
? ? ? ?document.getElementById("txt").removeAttribute"style";
? ? ?}else{
? ? ??
? ? ?}
? ? ?</script>
? </body>
</html>
這是我的代碼,想問下為什么我按每個按鈕都沒作用?
你把方法名改成小寫試試
那應該是你的函數名字和onclick名字不對應導致沒反應,仔細匹配對照一下,應該就好了
加了,試過好多次,只有把這部分代碼刪了其他就起作用了。
xuanlovexbx
是不是數值后面忘記加px了,我有一次就是這個錯誤,還有仔細檢查一下,代碼有木有字面錯誤,正常都該好使的,就檢查你要加的改變寬高的函數。width="30px"...
舉報
JavaScript做為一名Web工程師的必備技術,本教程讓您快速入門
5 回答點擊按鈕沒作用
4 回答為啥取消設置點擊確認按鈕不起作用呀
1 回答按鈕沒有起作用?
1 回答為什么我的按鈕不起作用?
1 回答點擊按鈕 不能運行= =
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-09-21
<!DOCTYPE html>
<html>
? <head>
? ? <title>javascript</title>
<style type="text/css">
body{
font-size:15px;
}
#txt{
height:400px;
width:600;
border:#333 solid 1px;
padding:5px;
}
p{
line-height:18px;
text-indent:2em;
}
</style>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
? ? ?</head>
??
? <body>
? ? <h2 id="con">JavaScript課程</h2>
? ? <div id="txt">
? ? <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="hidetxt()"/>
? ? <input type="button" value="顯示內容" onclick="showtxt()"/>
? ? <input type="button" value="取消設置" onclick="cs()"/>
? ? ? </form>
? ? ? <script type="text/javascript">
? ? var mychar=document.getElementById("txt");
? ? function changecolor(){
? ? ?mychar.style.color="red";
? ? }
? ? function changewh(){
? ? mychar.style.width="800px";
? ? mychar.style.height="200px";
? ? }
? ? function hidetxt(){
? ? ?mychar.style.display="none";
? ? }
? ??
? ? function showtxt(){
? ? ?mychar.style.display="block";
? ? }
? ? function cs(){
? ? var flag=confirm("取消設置?");
? ? if(flag==true){
? ? ? ?document.getElementById("txt").removeAttribute"style";
? ? ?}else{
? ? ??
? ? ?}
? ? }
? ? ?</script>
? ??
? </body>
</html>
這是我的代碼,想問下為什么我按每個按鈕都沒作用?
2017-08-31
你把方法名改成小寫試試
2017-08-29
那應該是你的函數名字和onclick名字不對應導致沒反應,仔細匹配對照一下,應該就好了
2017-08-29
加了,試過好多次,只有把這部分代碼刪了其他就起作用了。
2017-08-29
是不是數值后面忘記加px了,我有一次就是這個錯誤,還有仔細檢查一下,代碼有木有字面錯誤,正常都該好使的,就檢查你要加的改變寬高的函數。width="30px"...