JS入門問題___4-1編程挑戰(zhàn)
為什么最后調(diào)用清除樣式屬性時(shí),不會(huì)移除內(nèi)部式(嵌入式)中的樣式,而只會(huì)移除在JS中改變的樣式???
如下為內(nèi)部式定義的樣式:
<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>
如下為JS中改變的樣式:
//定義"改變顏色"的函數(shù)
function changeColor(){
??????? document.getElementById("con").style.color="blue";
??????? document.getElementById("txt").style.color="red";
??????? document.getElementById("con").style.backgroundColor="yellow";
??????? document.getElementById("txt").style.backgroundColor="black";
??? }
??? //定義"改變寬高"的函數(shù)
??? function changeWH(){
??????? document.getElementById("con").style.width="200px";
??????? document.getElementById("con").style.height="30px";
??????? document.getElementById("txt").style.width="300px";
??????? document.getElementById("txt").style.height="500px";
??? }
??? //定義"隱藏內(nèi)容"的函數(shù)
??? function hide(){
??????? document.getElementById("txt").style.display="none";? ?
??? }
??? //定義"顯示內(nèi)容"的函數(shù)
??? function show(){
??????? document.getElementById("txt").style.display="block";
??? }
????最后清除樣式屬性:
?function cancelSet(){
??????? var boolTF=confirm("是否取消全部設(shè)置");
??????? if(boolTF==true){
??????????? var title=document.getElementById("con");
??????????? var content=document.getElementById("txt");
??????????? // title.removeAttribute("style");
??????????? // content.removeAttribute("style");
??????????? // title.style=null;
??????????? // content.style=null;
??????????? title.style="";
??????????? content.style="";
??????? }
??? }
為什么最后調(diào)用清除樣式屬性時(shí),不會(huì)移除內(nèi)部式(嵌入式)中的樣式,而只會(huì)移除在JS中改變的樣式???求解答
2017-07-18