同樣的代碼格式執(zhí)行不了
//定義"改變顏色"的函數(shù)
? ? function color1(){
? ? var mychara=document.getElementById("txt");
? ? mychara.style.color="red";
? ? mychara.style.backgroundColor="blue";
? ? }
//定義"改變寬高"的函數(shù)
? ? function width1(){
? ? ? ? var mycharb=document.getElementById("txt");
? ? ? ? mycharb.style.width="100px";
? ? ? ? mycharb.style.height="100px";
? ? }
//定義"隱藏內(nèi)容"的函數(shù)
? ? function hide(){
? ? ? ? var mycharc=document.getElementById("txt");
? ? ? ? mycharc.style.display="none";
? ? }
//定義"顯示內(nèi)容"的函數(shù)
? ? function show(){
? ? ? ? var mychard=document.getElementById("txt");
? ? ? ? mychard.style.display="block";
//定義"取消設(shè)置"的函數(shù)
? ? function conf(){
? ? ? ? var mycharf=document.getElementById("txt");
? ? ? ? var mychare=confirm("取消設(shè)置");
? ? ? ? if(mychare==true){
? ? ? ? ? ? mychare.removeAttribute("style");
? ? ? ? }else
? ? ? ? {
? ? ? ? ? ? mycharf.className="null";
? ? ? ? }
? ? }
2016-11-15
定義函數(shù)以后,必須給每個(gè)按鈕添加相應(yīng)的onclick事件!
例:<input type="button" value="改變顏色" onclick="color1()" >
解析:函數(shù)相當(dāng)于是一款款工具,添加事件相當(dāng)是告訴電腦在什么時(shí)間用什么工具做什么事。