利用js改变htmll的属性

来源:互联网 发布:什么是网络推广专员 编辑:程序博客网 时间:2024/06/08 11:21

JavaScript可以改变html中的属性以改变《body》的颜色为例:

body id="bg"><script>    function bfcolor(color){//有参方法    document.getElementById("bg").style.backgroundColor=color;}//获得该元素</script><input  type="button"  onclick="bfcolor('#ff0000');" value="色彩"/><-改变颜色->

改变img中的图片

<script>function shif(t){    document.getElementById("ss").src=t;}</script>
<img id="ss" src="1.jpg" width="100"  height="100px" />//原图片1.jpg    <input type="button" onclick="shif('2.jpg')" value="替换" />//替换后的图片2.jpg