初识DOM

初始DOM
dom文档对象模型.
dom树document-->html
文档对象:整个html文件就是一个文档对象
根元素:html
元素:html的标签,也是一个对象
节点:网页中所有的内容都是节点(标签,属性,文本,注释等)
属性:标签的属性
体验dom操作
//dom:操作页面元素的
1.第一种写法:js代码在标签中完成
<input type="button" value="点击我" onclick="alert('hello')">
2.第二种写法,没有完全分离,调用函数存在同名
<input type="button" value="点击我222" onclick="alert('hello')">
<script>
function f1(){
alert("nihao");
alert("hello");
}
</script>
3.第三种,内容和行为完全分离,
<input type="button" value="点击我333" id="mybtn">
<script>
function f1(){
alert("你好");
alert("hello");
}
function f1(){
alert("呵呵哒");
}
//获取按钮元素(标签)---getElementById
//onclick:点击事件
//事件:就是一件事,有触发和响应,事件源
//按钮:事件源
//点击:事件名字
//被点了:触发这个点的事件
//弹框:响应
document.getElementById("mybtn").onclick=function(){
alert("最标准的事件处理");}
</script>
 

猜你喜欢

转载自blog.csdn.net/weixin_44740410/article/details/88824921
DOM