取消設(shè)置這個(gè)功能跟其他功能會(huì)沖突嗎?
我改變顏色,設(shè)置之后,使用取消設(shè)置回歸初始設(shè)置。但是無法再次使用改變顏色,寬高等功能了,請(qǐng)問這是什么原因???這個(gè)只是一次性的嗎?
我的代碼如下,謝謝。?
<input type="button" value="改變顏色" onclick="changecolor()" > ?
? ? <input type="button" value="改變寬高" onclick="changesize()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="hidetext()">
? ? <input type="button" value="顯示內(nèi)容" onclick="showtext()">
? ? <input type="button" value="取消設(shè)置" onclick="setoff()">
? </form>
? <script type="text/javascript">
var mychar=document.getElementById("txt");
//定義"改變顏色"的函數(shù)
function changecolor()
{mychar.style.color="red";
mychar.style.backgroundColor="#CCC";
}
//定義"改變寬高"的函數(shù)
function changesize(){
? ? mychar.style.width="800px";
? ? mychar.style.height="600px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function hidetext(){
? ? mychar.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function showtext(){
? ? mychar.style.display="block";
}
//定義"取消設(shè)置"的函數(shù)
function setoff(){
? ? var message=confirm("是否要取消設(shè)置?");
? ? if(message===true){
? ? ? ? mychar.removeAttribute("style");
? ? }
}
2015-09-01
<form id="txt">
<input type="button" value="改變顏色" onclick="changecolor()" > ?
? ? <input type="button" value="改變寬高" onclick="changesize()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="hidetext()">
? ? <input type="button" value="顯示內(nèi)容" onclick="showtext()">
? ? <input type="button" value="取消設(shè)置" onclick="setoff()">
? </form>
? <script type="text/javascript">
var mychar=document.getElementById("txt");
//定義"改變顏色"的函數(shù)
function changecolor()
{mychar.style.color="red";
mychar.style.backgroundColor="#CCC";
}
//定義"改變寬高"的函數(shù)
function changesize(){
? ? mychar.style.width="800px";
? ? mychar.style.height="600px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function hidetext(){
? ? mychar.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function showtext(){
? ? mychar.style.display="block";
}
//定義"取消設(shè)置"的函數(shù)
function setoff(){
? ? var message=confirm("是否要取消設(shè)置?");
? ? if(message===true){
? ? ? ? mychar.removeAttribute("style");
? ? }
}
</script>
2015-09-02
為什么確定后恢復(fù)不到原界面
2015-09-01
不會(huì)沖突,也不是一次性的,檢查一下你的代碼
2015-09-01
var mychar=document.getElementById("txt");
你指定的ID呢?