課程
/前端開發(fā)
/JavaScript
/JavaScript入門篇
為啥加上改變寬高的函數(shù)之后,點(diǎn)擊任何按鈕都不起作用?
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使網(wǎng)頁顯示動(dòng)態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</h5>
? ? <p >1.
? ? javascript入門篇,讓不懂js的你,快速了解js。</p>
? ? <p>2.
? ? JavaScript進(jìn)階篇,讓你掌握js的基礎(chǔ)語法,函數(shù),數(shù)組,事件,內(nèi)置對(duì)象,bom瀏覽器
? ? dom操作</p>
? ? <p>3.
? ? 學(xué)完以上兩門基礎(chǔ)課程后,在深入學(xué)習(xí)javascript的變量作用域,事件,對(duì)象、運(yùn)動(dòng)、cookie、
? ? 正則表達(dá)式、ajax等課程</p>
? ? </div>
? ? <form >
? ? <input type="button" value="改變顏色" onclick="changecolor()"/>
? ? <input type="button" value="改變寬高" onclick="changewh()"/>
? ? <input type="button" value="隱藏內(nèi)容" onclick="hidetxt()"/>
? ? <input type="button" value="顯示內(nèi)容" onclick="showtxt()"/>
? ? <input type="button" value="取消設(shè)置" 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("取消設(shè)置?");
? ? if(flag==true){
? ? ? ?document.getElementById("txt").removeAttribute"style";
? ? ?}else{
? ? ??
? ? ?}
? ? ?</script>
? </body>
</html>
這是我的代碼,想問下為什么我按每個(gè)按鈕都沒作用?
你把方法名改成小寫試試
那應(yīng)該是你的函數(shù)名字和onclick名字不對(duì)應(yīng)導(dǎo)致沒反應(yīng),仔細(xì)匹配對(duì)照一下,應(yīng)該就好了
加了,試過好多次,只有把這部分代碼刪了其他就起作用了。
xuanlovexbx
是不是數(shù)值后面忘記加px了,我有一次就是這個(gè)錯(cuò)誤,還有仔細(xì)檢查一下,代碼有木有字面錯(cuò)誤,正常都該好使的,就檢查你要加的改變寬高的函數(shù)。width="30px"...
舉報(bào)
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門
5 回答點(diǎn)擊按鈕沒作用
4 回答為啥取消設(shè)置點(diǎn)擊確認(rèn)按鈕不起作用呀
1 回答按鈕沒有起作用?
1 回答為什么我的按鈕不起作用?
1 回答點(diǎn)擊按鈕 不能運(yùn)行= =
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
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使網(wǎng)頁顯示動(dòng)態(tài)效果并實(shí)現(xiàn)與用戶交互功能。</h5>
? ? <p >1.
? ? javascript入門篇,讓不懂js的你,快速了解js。</p>
? ? <p>2.
? ? JavaScript進(jìn)階篇,讓你掌握js的基礎(chǔ)語法,函數(shù),數(shù)組,事件,內(nèi)置對(duì)象,bom瀏覽器
? ? dom操作</p>
? ? <p>3.
? ? 學(xué)完以上兩門基礎(chǔ)課程后,在深入學(xué)習(xí)javascript的變量作用域,事件,對(duì)象、運(yùn)動(dòng)、cookie、
? ? 正則表達(dá)式、ajax等課程</p>
? ? </div>
? ? <form >
? ? <input type="button" value="改變顏色" onclick="changecolor()"/>
? ? <input type="button" value="改變寬高" onclick="changewh()"/>
? ? <input type="button" value="隱藏內(nèi)容" onclick="hidetxt()"/>
? ? <input type="button" value="顯示內(nèi)容" onclick="showtxt()"/>
? ? <input type="button" value="取消設(shè)置" 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("取消設(shè)置?");
? ? if(flag==true){
? ? ? ?document.getElementById("txt").removeAttribute"style";
? ? ?}else{
? ? ??
? ? ?}
? ? }
? ? ?</script>
? ??
? </body>
</html>
這是我的代碼,想問下為什么我按每個(gè)按鈕都沒作用?
2017-08-31
你把方法名改成小寫試試
2017-08-29
那應(yīng)該是你的函數(shù)名字和onclick名字不對(duì)應(yīng)導(dǎo)致沒反應(yīng),仔細(xì)匹配對(duì)照一下,應(yīng)該就好了
2017-08-29
加了,試過好多次,只有把這部分代碼刪了其他就起作用了。
2017-08-29
是不是數(shù)值后面忘記加px了,我有一次就是這個(gè)錯(cuò)誤,還有仔細(xì)檢查一下,代碼有木有字面錯(cuò)誤,正常都該好使的,就檢查你要加的改變寬高的函數(shù)。width="30px"...