监听事件
1 btn.onclick = function (ev1) { 2 // alert(0); 3 window.location.href = 'http://www.itlike.com'; 4 }; 5 btn.onclick = function (ev1) { 6 // alert(1); 7 window.location.href = 'http://www.baidu.com'; 8 }; 9 btn.onclick = function (ev1) { 10 // alert(1); 11 window.location.href = 'http://www.tmall.com'; 12 } 13 14 后面的会覆盖前面的事件
1 window.onload = function (ev) { 2 var btn = document.getElementById('btn'); 3 btn.onclick = function (ev1) { 4 // alert(0); 5 window.location.href = 'http://www.itlike.com'; 6 }; 7 btn.onclick = function (ev1) { 8 // alert(1); 9 window.location.href = 'http://www.baidu.com'; 10 }; 11 btn.onclick = function (ev1) { 12 // alert(1); 13 window.location.href = 'http://www.tmall.com'; 14 } 15 16 17 btn.addEventListener('click', function (ev1) { 18 alert(0); 19 }); 20 21 btn.addEventListener('click', function (ev1) { 22 alert(1); 23 }); 24 25 btn.addEventListener('click', function (ev1) { 26 alert(2); 27 }) 28 }
0 1 2 跳转页面