更新节点
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id ="id1"></div>
<script>
var id1 = document.getElementById("id1");
</script>
</body>
</html>
操作文本
- id1.innerText=“456” 修改文本的值
- id1.innerHTML=“123”; 可以解析HTML文本标签
操作css
id1.style.color='yellow';//属性使用字符串包裹
id1.style.fontSize ='20px';// - 转 驼峰命名问题
id1.style.padding='2em';
彩蛋
1.idea中新建HTML无自动缩进
解决方法:editor->code style->HTML->other->Do not indent children of
删掉这几项就可以了。
2.通过js操作百度首页“百度一下”的按背景颜色
核心代码:
var su = document.getElementById('su');
undefined
su.style.background('orange')
VM352:1 Uncaught TypeError: su.style.background is not a function
at <anonymous>:1:10
(anonymous) @ VM352:1
su.style.backgroundColor='orange';
'orange'