JS實現(xiàn)改變HTML上文字顏色和內容的方法
本文實例講述了JS實現(xiàn)改變HTML上文字顏色和內容的方法。分享給大家供大家參考,具體如下:
1. JavaScript
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Day 1 </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script> // to change the color of an object. function changeColor(){ x=document.getElementById("Id1"); x.style.color="Red"; } // to change the content of an object. function changeContent(){ y=document.getElementById("Id2"); y.innerHTML="Hi, you have changed the contents using Java Script successfully!"; } </script> </HEAD> <BODY bgcolor="AntiqueWhite"> <h1 ><center>Welcome Page</center></h1> <p id="Id1">It is test 1.</p> <p id="Id2">It is test 2.</p> <button type="button" onclick ="changeColor()"> Change color of test 1 </button><br/><br/> <button type="button" onclick ="changeContent()"> Change content of test 2 </button> </BODY> </HTML>
2. Day 1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Day 1 </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script> // to change the color of an object. function changeColor(){ x=document.getElementById("Id1"); x.style.color="Red"; } // to change the content of an object. function changeContent(){ y=document.getElementById("Id2"); y.innerHTML="Hi, you have changed the contents using Java Script successfully!"; } </script> </HEAD> <BODY bgcolor="AntiqueWhite"> <h1 ><center>Welcome Page</center></h1> <p id="Id1">It is test 1.</p> <p id="Id2">It is test 2.</p> <button type="button" onclick ="changeColor()"> Change color of test 1 </button><br/><br/> <button type="button" onclick ="changeContent()"> Change content of test 2 </button> </BODY> </HTML>
3. 運行效果截圖:
PS:這里再提供幾款文字特效工具供大家參考:
在線特效文字/彩色文字生成工具:
http://tools.jb51.net/aideddesign/colortext
在線生成字體CSS樣式工具:
http://tools.jb51.net/code/csscreate
仿古書排版文字豎排轉換工具:
http://tools.jb51.net/transcoding/shupai
線條字生成工具:
http://tools.jb51.net/transcoding/xiantiaozi
在線鋼筆手寫體/手寫字生成工具:
http://tools.jb51.net/aideddesign/shouxiezi
更多關于JavaScript相關內容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結》、《JavaScript遍歷算法與技巧總結》、《JavaScript查找算法技巧總結》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調試技巧總結》、《JavaScript數據結構與算法技巧總結》及《JavaScript數學運算用法總結》
希望本文所述對大家JavaScript程序設計有所幫助。
相關文章
Javascript 鍵盤事件的組合使用實現(xiàn)代碼
Javascript 鍵盤事件的組合使用實現(xiàn)代碼,需要的朋友可以參考下2012-05-05