課程
/前端開(kāi)發(fā)
/JavaScript
/JavaScript入門(mén)篇
比如我設(shè)置了大小,再設(shè)置顏色,點(diǎn)取消設(shè)置按鈕是都取消,回初始樣式,能不能回上一步,就不是回初始樣式
2016-05-10
源自:JavaScript入門(mén)篇 4-1
正在回答
//定義"改變顏色"的函數(shù)
?var txt = document.getElementById("txt");
?var flag = "";
function changeColor(){
? ? ? txt.style.color="red";
? ? ? txt.style.backgroundColor='blue';
? ? ? flag = 1;
}
//定義"改變寬高"的函數(shù)
function changeSize(){
? ? ?txt.style.width="500px";
? ? ?txt.height="300px";
? ? ?flag ?= 2;
//定義"隱藏內(nèi)容"的函數(shù)
function hideContent(){
? ? txt.style.display="none";
? ? flag = 3;
//定義"顯示內(nèi)容"的函數(shù)
function showContent(){
? ? txt.style.display = "block";
//定義"取消設(shè)置"的函數(shù)
function cancelSet(){
? ? if(confirm("是否取消設(shè)置嗎")){
? ? ? ? if(flag=="1"){
? ? ? ? ? ?txt.style.color="#000";
? ? ? ? ? ?txt.style.backgroundColor='white';
? ? ? ? }else if(flag=="2"){
? ? ? ? ? txt.style.width="600px";
? ? ? ? ? txt.style.height="400px";
? ? ? ? }else if(flag=="3"){
? ? ? ? ? ? txt.style.display = "block";
? ? ? ? }
? ? ? ??
? ? }
龍TT 提問(wèn)者
我是這樣改的concel.style="txt";
取消設(shè)置按鈕其實(shí)就是將樣式修改成初始的樣式。你可以加一個(gè)值做標(biāo)記,比如如果你設(shè)置了大小,那你就把這個(gè)值設(shè)為1,如果你設(shè)置了顏色,那你就把值設(shè)為2,然后取消設(shè)置的時(shí)候判斷,如果是1,那么上一步就是設(shè)置了大小,你就只將大小還原成初始樣式,這樣也就等同于回上一步了。
舉報(bào)
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門(mén)
3 回答關(guān)于取消設(shè)置
1 回答關(guān)于取消設(shè)置
1 回答求教 關(guān)于取消設(shè)置
1 回答關(guān)于取消設(shè)置按鈕的設(shè)置
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-05-10
//定義"改變顏色"的函數(shù)
?var txt = document.getElementById("txt");
?var flag = "";
function changeColor(){
? ? ? txt.style.color="red";
? ? ? txt.style.backgroundColor='blue';
? ? ? flag = 1;
}
//定義"改變寬高"的函數(shù)
function changeSize(){
? ? ?txt.style.width="500px";
? ? ?txt.height="300px";
? ? ?flag ?= 2;
}
//定義"隱藏內(nèi)容"的函數(shù)
function hideContent(){
? ? txt.style.display="none";
? ? flag = 3;
}
//定義"顯示內(nèi)容"的函數(shù)
function showContent(){
? ? txt.style.display = "block";
}
//定義"取消設(shè)置"的函數(shù)
function cancelSet(){
? ? if(confirm("是否取消設(shè)置嗎")){
? ? ? ? if(flag=="1"){
? ? ? ? ? ?txt.style.color="#000";
? ? ? ? ? ?txt.style.backgroundColor='white';
? ? ? ? }else if(flag=="2"){
? ? ? ? ? txt.style.width="600px";
? ? ? ? ? txt.style.height="400px";
? ? ? ? }else if(flag=="3"){
? ? ? ? ? ? txt.style.display = "block";
? ? ? ? }
? ? ? ??
? ? }
}
2016-05-10
我是這樣改的concel.style="txt";
2016-05-10
取消設(shè)置按鈕其實(shí)就是將樣式修改成初始的樣式。你可以加一個(gè)值做標(biāo)記,比如如果你設(shè)置了大小,那你就把這個(gè)值設(shè)為1,如果你設(shè)置了顏色,那你就把值設(shè)為2,然后取消設(shè)置的時(shí)候判斷,如果是1,那么上一步就是設(shè)置了大小,你就只將大小還原成初始樣式,這樣也就等同于回上一步了。