關(guān)于取消設(shè)置的問題
把#txt改成 .txt
<style type="text/css">
body{font-size:12px;}
.txt{
? ? height:400px;
? ? width:600px;
????border:#333 solid 1px;
????padding:5px;}
?p{
?????line-height:18px;
?????text-indent:2em;}
</style>
下面是取消設(shè)置方法,但是沒效果,麻煩看一下哪里錯(cuò)了?
? function cancel(){
? ? ? ? var q=confirm("是否確定取消設(shè)置?")
? ? ? ? if(q==true){
? ? ????? ? last.className="txt";
? ? ? ? }
還有有的人寫的取消設(shè)置,txt.removeAttribute('style');,這個(gè)是什么意思?
2016-04-21
按照你的思路是要用修改css樣式來恢復(fù)設(shè)置,那么:
第一步:id不能直接改成類名,需要增加一個(gè)類名,因?yàn)閒unction里面用的是getElementById,如果改成類名,那就獲取不到參數(shù)了:
<div id="txt"> 修改為 <div id="txt" class="con">
第二步:#txt修改為.con,增加.con2,文本原來用的就是.con的樣式,然后你調(diào)用function的時(shí)候修改的也是.con的樣式,也就是.con樣式是已經(jīng)被修改了不再是原來的數(shù)據(jù)(雖然css里面看上去沒變),所以按照你的思路,需要寫一個(gè)新的樣式去覆蓋;
.con{
? ? height:400px;
? ? width:600px;
????border:#333 solid 1px;
????padding:5px;}
con2{
? ? height:400px;
? ? width:600px;
????border:#333 solid 1px;
????padding:5px;}
第三步:覆蓋新樣式,這樣就會(huì)被替換了
?function cancel(){
? ? ? ? var q=confirm("是否確定取消設(shè)置?");
? ? ? ? if(q==true){
? ? ? ? ? ? var last = document.getElementById("txt");
? ? ????? ? last.className="con2";?
? ? ? ? }
另外:txt.removeAttribute('style'); txt是獲取的對(duì)象,removeAttribute('style')是清除所有style設(shè)置,意會(huì)應(yīng)該就能明白吧……
2016-04-21
function cancel(){
? ? ? ? var q=confirm("是否確定取消設(shè)置?")
? ? ? ? if(q==true)
? ? ? {
? ? ????? q.removeAttribute("style"};
? ? ? ? }