阻止冒泡
非IE下:event.stopPropagation();
IE下:event.cancelBubble=true;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <div id="aaa"> 点击我 <div id="bbb"> 点击我 </div> </div> <script> var da=document.getElementById('aaa'); var xiao=document.getElementById('bbb'); da.onclick=function(e){ var ao=eevent; ao.stopPropagation(); ao.cancelBubble==true; alert('大盒子'); } xiao.onclick=function(e){ var ao=eevent; ao.stopPropagation(); ao.cancelBubble==true; alert('小盒子'); } </script>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <input type="button" value="点击按钮" id="btn"> <div id="zs"></div> <script> var btn=document.getElementById('btn'); var hz=document.getElementById('zs'); btn.onclick=function(e){ var bo=eevent; bo.stopPropagation(); hz.style.display='block'; } document.onclick=function(){ hz.style.display='none'; } </script>
|
JS计时事件
计时器setInterval与clearInterval
1 2 3 4 5 6 7 8 9 10 11 12 13
| <button onclick="func()">点击开始</button> <button onclick="fund()">点击结束</button> <script>
var aa; function func(){ aa=window.setInterval("alert('间隔一秒弹出内容');",3000); } function fund(){ window.clearInterval(aa); } </script>
|
计时器setTimeout与clearTimeout
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <button onclick="funf()">点击开始</button> <button onclick="fune()">点击结束</button> <script>
var ff; function funf(){ ff=setTimeout(function(){ alert('你好') },3000) } function fune(){ clearTimeout(ff); } </script>
|