JavaScript不用获取元素,直接通过id操作dom
任意写一个div,任意设置id test
打印出window对象,发现window.document.all下面挂载了test
使用document.getElementById('test')获取id为test的元素
因为window是默认的全局对象,所以可以简写,原来是window.document.getElementById()
console.log(window.document.all.test===window.document.getElementById('test')) //true

浙公网安备 33010602011771号