BOM
JavaScript分三個部分:
1. ECMAScript標準---基本語法 2. DOM--->Document Object Model 檔案物件模型,操作頁面元素的 3. BOM--->Browser Object Model 瀏覽器物件模型, 操作瀏覽器的 瀏覽器中有個頂級物件
:window----皇上 頁面中頂級物件:document-----總管太監 頁面中所有的內容都是屬于瀏覽器的,頁面中的內容也都是window的 變數是window的系統對話框
---知道window.alert("您好啊");//以后不用,測驗的時候使用
window.prompt("請輸入帳號");
var result = window.confirm("您確定退出嗎"); console.log(result);
加載事件
//頁面加載完畢了,再獲取按鈕 //只要頁面加載完畢,這個事件就會觸發-----頁面中所有的內容,標簽,屬性,文本,包括外部引入js檔案 window.onload = function () { document.getElementById("btn").onclick = function () { alert("您好"); }; };
Location物件
//物件中的屬性和方法 location物件 console.log(window.location);
//地址欄上#及后面的內容 console.log(window.location.hash); //主機名及埠號 console.log(window.location.host); //主機名 console.log(window.location.hostname); //檔案的路徑---相對路徑 console.log(window.location.pathname); //埠號 console.log(window.location.port); //協議 console.log(window.location.protocol); //搜索的內容 console.log(window.location.search);
設定跳轉的頁面的地址
location.href----屬性
方法:
location.assign
location.reload
l
onl oad = function () { document.getElementById("btn").onclick = function () { //設定跳轉的頁面的地址 location.href="http://www.jd.com";//屬性----------------->必須記住 //location.assign("http://www.jd.com");//方法 //location.reload();//重新加載--重繪 //location.replace("http://www.jd.com");//沒有歷史記錄 }; };
history物件
//跳轉的 my$("btn1").onclick = function () { window.location.href = "15test.html"; }; //前進 my$("btn2").onclick = function () { window.history.forward(); };
navigator物件
n
navigator.platform 平臺型別
//通過userAgent可以判斷用戶瀏覽器的型別 console.log(window.navigator.userAgent); //通過platform可以判斷瀏覽器所在的系統平臺型別. console.log(window.navigator.platform);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/164086.html
標籤:JavaScript
下一篇:vue解惑之slot(插槽)
