本文实例讲述了JS实现改变HTML上文字颜色和内容的方法。分享给大家供大家参考,具体如下:
1. JavaScript
Day 1// 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!";
}
It is test 1.
It is test 2.
Change color of test 1
Change content of test 2
2. Day 1.html
Day 1// 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!";
}
It is test 1.
It is test 2.
Change color of test 1
Change content of test 2
3. 运行效果截图:
PS:这里再提供几款文字特效工具供大家参考:
希望本文所述对大家JavaScript程序设计有所帮助。