css、js控制html标签的属性和内容

css.html

<!DOCTYPE html>
<html>
<head>
    <title>js控制html标签的属性和内容</title>
    <style type="text/css">
        #box01{width: 100px;height: 100px;background:pink;}
    </style>
</head>
<body>
    <div id="box01" title="我是title属性" class="class01">我是一个div盒子</div>

</body>
</html>

这里写图片描述

js.html

<!DOCTYPE html>
<html>
<head>
    <title>js控制html标签的属性和内容</title>
    <style type="text/css">
        #box01{width: 100px;height: 100px;background:pink;}
    </style>
</head>
<body>
    <div id="box01" title="我是title属性" class="class01">我是一个div盒子</div>

</body>
</html>
<script type="text/javascript">
    //1.先获得指定的id属性
    var box01 = document.getElementById('box01');
    //2.改变div中的title属性
    box01.title = '我是被js改变的title';
    //2.改变class的属性
    box01.className = 'class02';
    //3.改变div显示的内容
    box01.innerHTML = '我是被js修改的html属性'
</script>

这里写图片描述

 

上述代码各自粘贴进入txt文本后,然后重命名如上,双击打开即可见效。

其中script type的意思是下面的代码是什么语法

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值