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數(shù)據(jù)結構與算法技巧總結》及《JavaScript數(shù)學運算用法總結》
希望本文所述對大家JavaScript程序設計有所幫助。
- JS數(shù)組返回去重后數(shù)據(jù)的方法解析
- js實現(xiàn)復選框的全選和取消全選效果
- 原生JS實現(xiàn)在線問卷調查投票特效
- 通過AngularJS實現(xiàn)圖片上傳及縮略圖展示示例
- 非常優(yōu)秀的JS圖片輪播插件Swiper的用法
- JS實現(xiàn)簡單的二元方程計算器功能示例
- Angularjs使用ng-repeat中$even和$odd屬性的注意事項
- Angularjs通過指令監(jiān)聽ng-repeat渲染完成后執(zhí)行腳本的方法
- angularjs中ng-attr的用法詳解
- JS實現(xiàn)類似百葉窗下拉菜單效果
- javascript 注釋代碼的幾種方法總結
相關文章
Javascript 鍵盤事件的組合使用實現(xiàn)代碼
Javascript 鍵盤事件的組合使用實現(xiàn)代碼,需要的朋友可以參考下2012-05-05js bind 函數(shù) 使用閉包保存執(zhí)行上下文
在javascript中,函數(shù)總是在一個特殊的上下文執(zhí)行(稱為執(zhí)行上下文),如果你將一個對象的函數(shù)賦值給另外一個變量的話,這個函數(shù)的執(zhí)行上下文就變?yōu)檫@個變量的上下文了。下面的一個例子能很好的說明這個問題2011-12-12