課程
/前端開發(fā)
/JavaScript
/JavaScript入門篇
求大神指導。
2016-08-20
源自:JavaScript入門篇 4-1
正在回答
? <form>
? <!--當點擊相應按鈕,執(zhí)行相應操作,為按鈕添加相應事件-->
? ? <input type="button" value="改變顏色" onclick="changecolor()"> ?
? ? <input type="button" value="改變寬高" onclick="changewh()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="hide()">
? ? <input type="button" value="顯示內(nèi)容" onclick="disp()">
? ? <input type="button" value="取消設置" onclick="canc()">
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
function changecolor()
{
? ? var obj=document.getElementById("txt");
? ? obj.style.color="red";
? ? obj.style.background="blue";
}
//定義"改變寬高"的函數(shù)
function changewh()
? ? obj.style.width="200px";
? ? obj.style.height="600px";
//定義"隱藏內(nèi)容"的函數(shù)
function hide()
? ? obj.style.display="none";
//定義"顯示內(nèi)容"的函數(shù)
function disp()
? ? obj.style.display="block";
//定義"取消設置"的函數(shù)
function canc()
? ? var temp=confirm("是否恢復");
? ? if(temp)
? ? {
? ? ? ? var obj=document.getElementById("txt");
? ? ? ? obj.style.color="";
? ? ? ? obj.style.background="";
? ? ? ? obj.style.width="400px";
? ? ? ? obj.style.height="600px";
? ? ? ? obj.style.display="block";
? ? }
//例如只取消顏色 function?cancel(){ ???????var?a?=?document.getElementById("txt") ???????var?sure?=?confirm("Do?you?want?to?cancel?all?changes?"); ????????if(?sure?) ????????????a.style.color?=?"";?? ????????}???? ????}
舉報
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門
4 回答點擊按鈕取消,如何不出現(xiàn)提示框
4 回答如何實現(xiàn)取消設置?
2 回答點擊取消設置,彈出的確認框,我點擊取消,然而還是取消了之前的設置。
3 回答取消設置 按鈕
4 回答取消設置點擊取消后沒有反應
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-08-21
? <form>
? <!--當點擊相應按鈕,執(zhí)行相應操作,為按鈕添加相應事件-->
? ? <input type="button" value="改變顏色" onclick="changecolor()"> ?
? ? <input type="button" value="改變寬高" onclick="changewh()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="hide()">
? ? <input type="button" value="顯示內(nèi)容" onclick="disp()">
? ? <input type="button" value="取消設置" onclick="canc()">
? </form>
? <script type="text/javascript">
//定義"改變顏色"的函數(shù)
function changecolor()
{
? ? var obj=document.getElementById("txt");
? ? obj.style.color="red";
? ? obj.style.background="blue";
}
//定義"改變寬高"的函數(shù)
function changewh()
{
? ? var obj=document.getElementById("txt");
? ? obj.style.width="200px";
? ? obj.style.height="600px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function hide()
{
? ? var obj=document.getElementById("txt");
? ? obj.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function disp()
{
? ? var obj=document.getElementById("txt");
? ? obj.style.display="block";
}
//定義"取消設置"的函數(shù)
function canc()
{
? ? var temp=confirm("是否恢復");
? ? if(temp)
? ? {
? ? ? ? var obj=document.getElementById("txt");
? ? ? ? obj.style.color="";
? ? ? ? obj.style.background="";
? ? ? ? obj.style.width="400px";
? ? ? ? obj.style.height="600px";
? ? ? ? obj.style.display="block";
? ? }
}
2016-08-20