<!DOCTYPE html> <html> <head> <title>捕捉和冒泡</title> <meta charset="utf-8"> </head> <body> <style> #china{ width:500px; height: 500px; } div{ border: 1px solid #333; width:80%; height: 80%; margin: 10%; } </style> <div id="china"> 我是中国区域 <div id="shanxi"> 我是陕西区域 <div id="xian"> 我是西安区域 </div> </div> </div> <script> //获取中国,陕西,西安三大对象 var china =document.getElementById('china'); var shanxi=document.getElementById('shanxi'); var xian =document.getElementById('xian'); //第三个参数,是否捕捉,默认值是false,不捕捉即默认为冒泡【目前是捕捉模式】 // china.addEventListener('click',function(){console.log('China')},true); // shanxi.addEventListener('click',function(){console.log('Shanxi')},true); // xian.addEventListener('click',function(){console.log('Xian')},true); //第三个参数,是否捕捉,默认值是false,不捕捉即默认为冒泡【目前是冒泡模式】 china.addEventListener('click',function(){console.log('China')},false); shanxi.addEventListener('click',function(ev){ console.log('Shanxi'); ev.stopPropagation(); },false); xian.addEventListener('click',function(){console.log('Xian')},false); </script> </body> </html> 【主要方法】:stopPropagation()
window.setInterval(method,time)方法本身会返回一个资源句柄,使用clearInterval(Intervalid)方法即可清除定时器<script> var num=0; //每隔1秒再控制台输...
https://3gimg.qq.com/lightmap/v1/marker/index.html?marker=coord:37.6767600000,112.7297800000&key=TKUBZ-D24AF-GJ4JY-JDVM2-IBYKK-KEBCU&referer=p...
//构造函数 function Box(name,age){ this.name=name; this.age=age; this.run=function(){ return this.name+'--'+this.age; } } var&nbs...
//我们创建每个函数默认都有一个prototype(原型)属性,这个属性是一个对象 //1.我是普通的构造方法,我的属性叫实例属性,我的方法叫实例方法 /* function Box(name,age){ this.name=name; this.age=age; this.run...
//字面量的形式创建原型对象 /* function Box(){} Box.prototype={ 'name':'gao', age:23, fun:function(){ return this.name+'--'+...
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>点击复制</title> </head>...