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