js監聽鼠標點擊(onmousedown)和鍵盤點擊(onkeydown)事件並自動跳轉頁面,在學習的朋友可以參考下
$(function(){
var i = 0;
document.onmousedown=function(event){
if(i==1){
window.open('http://www.njxblog.com');
}
//setTimeout(function (){window.open('http://www.jb51.net')},2000); //定時不太好使,會被浏覽器當成廣告的
i++;
};
var j = 0;
document.onkeydown=function(event){
if(j==1){
window.open('http://www.njxblog.com');
}
//setTimeout(function (){window.open('http://www.jb51.net')},2000); //定時不太好使,會被浏覽器當成廣告的
j++;
};
});
PS:這裡再為大家推薦一款關於JS事件的在線查詢工具,歸納總結了JS常用的事件類型與函數功能:
javascript事件與功能說明大全:
http://tools.jb51.net/table/javascript_event