本文實例講述了JS實現改變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. 運行效果截圖:

相關推薦:
JS實現加載時鎖定HTML頁面元素的方法
js獲取html的span標簽的值方法(超簡單)
以上就是JS實現改變HTML上文字顏色和內容的方法的詳細內容,html教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答