我這些按鈕為什么一個都沒用啊啊啊啊啊 啊啊啊?
? <!--當(dāng)點(diǎn)擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
? ? <input type="button" value="改變顏色" onclick="changecolor()"> ?
? ? <input type="button" value="改變寬高" onclick="changesize()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="sethide()">
? ? <input type="button" value="顯示內(nèi)容" onclick="setshow()">
? ? <input type="button" value="取消設(shè)置" onclick="offset()">
? </form>
? <script type="text/javascript">
? var i=document.getElementById("con");
? var j=document.getElementById("txt");
? var set={
? ? ? function changecolor(){
? ? ? j.style.color="red";
? ? ? j.style.backgroundColor="#ccc";}
//定義"改變顏色"的函數(shù)
? ? ? ? function changesize(){
? ? ? ? ? ? j.style.width="200px";
? ? ? ? ? ? j.style.height="300px";}
//定義"改變寬高"的函數(shù)
? ? ? ? function sethide(){
? ? ? ? ? ? j.style.display="none";}
//定義"隱藏內(nèi)容"的函數(shù)
? ? ? ? function setshow(){
? ? ? ? ? ? j.style.display="block";}
//定義"顯示內(nèi)容"的函數(shù)
? ? ? ? function offset(){
? ? ? ? ? ? var message=confirm("是否取消設(shè)置?");
? ? ? ? ? ? if(message==true){
? ? ? ? ? ? ? ? j.removeAttribute("style");}
? ? ? ? }
? ? ?}
//定義"取消設(shè)置"的函數(shù)
2017-06-26
你干嘛要把標(biāo)題和內(nèi)容分成兩個變量??
我覺得你不應(yīng)該把你的函數(shù)都放在var set{}里面
//定義"改變顏色"的函數(shù)
var div=document.getElementById("txt");
function changcolor(){
??? div.style.color="red";
??? div.style.backgroundColor="black";
}
//定義"改變寬高"的函數(shù)
function changwh(){
??? div.style.width="500px";
??? div.style.heitht="1000px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function hidetext(){
??? div.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function showtext(){
??? div.style.display="block";
}
//定義"取消設(shè)置"的函數(shù)
function cancel(){
if(confirm("是否取消設(shè)置?")){
??? div.style="";
}}
2017-06-27
很好,謝謝。前面四個標(biāo)簽有效,最后一個取消設(shè)置的標(biāo)簽沒用
2017-06-24
每個按鈕點(diǎn)擊后只單獨(dú)執(zhí)行該函數(shù)里面的內(nèi)容,所以獲取id的代碼要寫在每個函數(shù)里面