js-可以使用id直接操作DOM

//一般不建议使用,可以在console调试时使用
<input type="button" id="btn" value="btn">
<input type="button" id="location" value="btn">
<script>
    btn.onclick=function(){
        console.log('hello');   //结果弹出 --hello
    }
    location.onclick=function(){
        console.log('location');  //无任何输出--因为window自带locaiton属性,此时window的location属性,覆盖了id为location的标签
    }
</script>

  

posted @ 2021-08-27 09:50  7c89  阅读(115)  评论(0)    收藏  举报