本文實例講述了JS實現(xiàn)改變HTML上文字顏色和內(nèi)容的方法。分享給大家供大家參考,具體如下:
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.VeVB.COm/aideddesign/colortext
在線生成字體CSS樣式工具:
http://tools.VeVB.COm/code/csscreate
仿古書排版文字豎排轉(zhuǎn)換工具:
http://tools.VeVB.COm/transcoding/shupai
線條字生成工具:
http://tools.VeVB.COm/transcoding/xiantiaozi
在線鋼筆手寫體/手寫字生成工具:
http://tools.VeVB.COm/aideddesign/shouxiezi
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》及《JavaScript數(shù)學(xué)運算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
新聞熱點
疑難解答