課程
/前端開發(fā)
/JavaScript
/JavaScript入門篇
取消設(shè)置運(yùn)用在是confirm,那么怎么恢復(fù)原始值
2016-03-03
源自:JavaScript入門篇 4-1
正在回答
這個(gè)案例最后的取消設(shè)置我還真是不太會(huì),看了你們的我才知道原來可以設(shè)置成最初始的樣子就可以了。
?var aaa=confirm('是否要取消設(shè)置');?????? if(aaa==true){?????????? txt.removeAttribute("style");?????? }else{?????????? return false;?????? }
if(window.confirm("是否取消")){object.removeAttribute("style");}
不要這么復(fù)雜
?var con=document.getElementById('txt').style;//定義"改變顏色"的函數(shù)??? ??? function changeColor(){??????? con.color="red";??????? con.backgroundColor="#ccc";??? }
//定義"改變寬高"的函數(shù)??? function changeHeight(){??????? con.width="200px";??????? con.height="300px";??? }
//定義"隱藏內(nèi)容"的函數(shù)??? function contentHiden(){??????? con.display="none";??? }
//定義"顯示內(nèi)容"的函數(shù)??? function viewContent(){??????? con.display="block";??? }
//定義"取消設(shè)置"的函數(shù)
??? function rest(){??????? var re=confirm("是否取消設(shè)置?");??????? if(re){??????????? con.cssText = "";??????? }??? }
把原來的屬性都寫一遍可以實(shí)現(xiàn)恢復(fù)。我也是初學(xué)者,應(yīng)該有其他方法。
function reSet(){
? ? ? ? var div=document.getElementById("txt");
? ? ? ? if(confirm("要取消設(shè)置嗎?")){
? ? ? ? ? ? div.style.color="#000";
? ? ? ? ? ? div.style.backgroundColor="#fff";
? ? ? ? ? ? div.style.width="400px";
? ? ? ? ? ? div.style.height="600px";
? ? ? ? ? ? div.style.display="block";
? ? ? ? }
? ? }
希望不滅99
舉報(bào)
JavaScript做為一名Web工程師的必備技術(shù),本教程讓您快速入門
7 回答取消設(shè)置 怎么設(shè)置恢復(fù)原始值
7 回答確認(rèn)取消設(shè)置,恢復(fù)原始值,怎么設(shè)置?
4 回答怎么恢復(fù)原始值?
4 回答怎么把在js中設(shè)置的樣式恢復(fù)原始值
1 回答怎么將所有的設(shè)置都恢復(fù)原始值
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-08-09
這個(gè)案例最后的取消設(shè)置我還真是不太會(huì),看了你們的我才知道原來可以設(shè)置成最初始的樣子就可以了。
2016-03-03
?var aaa=confirm('是否要取消設(shè)置');
?????? if(aaa==true){
?????????? txt.removeAttribute("style");
?????? }else{
?????????? return false;
?????? }
2016-03-03
if(window.confirm("是否取消")){object.removeAttribute("style");}
2016-03-03
不要這么復(fù)雜
?var con=document.getElementById('txt').style;
//定義"改變顏色"的函數(shù)
???
??? function changeColor(){
??????? con.color="red";
??????? con.backgroundColor="#ccc";
??? }
//定義"改變寬高"的函數(shù)
??? function changeHeight(){
??????? con.width="200px";
??????? con.height="300px";
??? }
//定義"隱藏內(nèi)容"的函數(shù)
??? function contentHiden(){
??????? con.display="none";
??? }
//定義"顯示內(nèi)容"的函數(shù)
??? function viewContent(){
??????? con.display="block";
??? }
//定義"取消設(shè)置"的函數(shù)
??? function rest(){
??????? var re=confirm("是否取消設(shè)置?");
??????? if(re){
??????????? con.cssText = "";
??????? }
??? }
2016-03-03
把原來的屬性都寫一遍可以實(shí)現(xiàn)恢復(fù)。我也是初學(xué)者,應(yīng)該有其他方法。
function reSet(){
? ? ? ? var div=document.getElementById("txt");
? ? ? ? if(confirm("要取消設(shè)置嗎?")){
? ? ? ? ? ? div.style.color="#000";
? ? ? ? ? ? div.style.backgroundColor="#fff";
? ? ? ? ? ? div.style.width="400px";
? ? ? ? ? ? div.style.height="600px";
? ? ? ? ? ? div.style.display="block";
? ? ? ? }
? ? }