事件對象(Event)
在觸發DOM事件的時候會產生一個對象
1.type: 獲取事件類型
2.target: 獲取時間目標
3.stopPropagation(): 阻止事件冒泡
4.preventDefault(): 阻止事件默認行為
<div id="div">
<button id="btn1" onclick="demo()">按鈕</button>
</div>
<script>
document.getElementById("btn1").addEventListener("click",showType);
document.getElementById("div").addEventListener("click",showDiv);
function showType(event){
//alert(event.type);
alert(event.target);
event.stopPropagation();//阻止事件冒泡
}
function showDiv(){
alert("div");
}
</script>
瀏覽器對象#
1.window對象######
window.innerWidth 瀏覽器窗口的內部寬度 不包含進度條
window.innerHeight 瀏覽器窗口的內部高度 不包含工具欄
window.open() 打開新窗口
window.open("index.html","標題","大小");
window.close() 關閉當前窗口
2.計時器
方法:
setInterval()間隔指定的毫秒數不停地執行指定的代碼
clearInterval()用于停止setInterval()方法執行的函數代碼
<button id="btn" onclick="stopTime()">按鈕</button>
<p id="ptime"></p>
<script>
var myTime = setInterval(function(){
getTime();
},1000);
function getTime(){
var d = new Date();
var t = d.toLocaleTimeString();
document.getElementById("ptime").innerHTML = t;
}
function stopTime(){
clearInterval(myTime);
}
</script>
setTimeout()暫停指定的毫秒數后執行的代碼
clearTimeout()用于停止執行setTimeout()方法的函數代碼
3.History對象
window.history 對象包含瀏覽器的歷史(url)的集合
方法:
history.back() 與在瀏覽器點擊后退按鈕相同
history.forward() 與在瀏覽器中點擊向前按鈕相同
history.go() 進入歷史中的某個頁面
EXP:
<button id="btn" onclick="goceshi()">按鈕</button>
<script>
function goceshi(){
history.back();
}
</script>
4.Location對象######
window.location 對象用于獲得當前頁面的地址(url),并把瀏覽器重定向到新的頁面
對象屬性:
location.hostname 返回web主機的域名
location.pathname 返回當前頁面的路徑和文件名
location.port 返回web主機的端口
location.protocol 返回所使用的web協議(http://或https://)
location.href 返回當前頁面的URL
location.assign() 加載新的文檔
window.location.hostname;
location.assign(url);
5.Screen對象
window.screen 對象包含有關用戶屏幕的信息
屬性:
screen.availWidth 可用的屏幕寬度
screen.availHeight 可用的屏幕高度
screen.Height 屏幕高度
screen.Width 屏幕寬度
<script>
document.write("可用高度:"+screen.availHeight+",可用寬度:"+screen.availWidth);
document.write("高度:"+screen.height+",寬度:"+screen.width);
</script>
最后編輯于 :2017.11.27 03:30:08
?著作權歸作者所有,轉載或內容合作請聯系作者 平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。