点击按钮文字变颜色
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title></title> 6 </head> 7 8 <body> 9 <p id="hello">hello</p> 10 <input type="button" style="cursor:pointer;" value="点击变颜色" onclick="hello()" /> 11 <br/> 12 </body> 13 14 <script language="javascript"> 15 var a= new Array(); 16 a[0]=2; 17 a[1]=1; 18 a[2]=3; 19 a.sort();/*从小到大排序*/ 20 a.reverse();/*数组翻转*/ 21 document.write(a);/*输出321*/ 22 23 var a=true; 24 function hello() 25 { 26 if(a) 27 { 28 x=document.getElementById("hello"); 29 x.style.color = "#ff0000"; 30 a=false; 31 } 32 else 33 { 34 y=document.getElementById("hello"); 35 y.style.color="#000000"; 36 a=true; 37 } 38 } 39 </script>
显示效果: