1. 程式人生 > >js復習:

js復習:

word 返回值 rem 屏蔽 nav 數學 瀏覽器 則表達式 set

JavaScript: 基本語法: 與c#語法基本一致,類型轉換:var a= parseint(值): var b = parsefloat(值); isNaN(值):判斷是否是數字,是返回false不是返回true;

函數方法:

// 無返回值

<script >

test1();

function test1(){

alert(‘hello word‘);

}

</script>

//有返回值:

<script >

var ccc = test1(5,6);

alert(ccc);

function test1(a,b){

var c = a+b;

renturn c;

}

</script>

JavaScript DOM:

windows對象: window.open() window.close() window.opener window.setinterval()/window.setTimeout(); 調整頁面: window.navigate("url"); window.moverTo(x,y); window.resizeTo(wid.hei); window.scrollTo(x,y);

window.open();

<input type="button" value="按鈕1" id="btn1"/>;

<script>

var oBtn1 = document.getElementById("btn1");

oBtn1.onclick = function(){

window.open("Default2.aspx","_blank","width=400 height=400 left="+((window.screen.width/2)-200)+" top=""+((window.screen.height/2)-200)+");

//window.screen.width 是屏幕的寬度

}

var oBtn2 = document.getElementById("btn2");

oBtn2.onclick = function(){

a.Close();

}

oBtn1.onclick = function(){

window.scrollTo(0,200);

}

// 往下調到200.相當於錨點

//將父級窗口關閉 widow.opener.close();

</script>

window.history 對象: window.history.back(); window.history.forward();

window.history.go(n); //放正數前進一個頁面,放負數後退一個頁面;

window.location對象: window.location.href="url"; //跳轉頁面 和window.open();相似;但是瀏覽器不會屏蔽他,open有的瀏覽器會屏蔽; 它還會獲取當前頁面的地址;

window.document對象:

{

獲取對象{

document.getElementById("id")

document.getElementsByClassName("class")

document.getElementsByName("name")

document.getElementsByTagName("標記")

}

操作對象屬性{

添加屬性:對象.setAttribute("name","value");

移除屬性:對象.removeAttribute("name");

獲取屬性值:對象.getAttribute("name");

}

操作對象內容{

對象.innerHTML=“” /對象.innerText ="";

innerHTML會將裏面寫的有關的代碼編譯出來而Text會將你寫的內容當做文本展示出來並不會編譯。

普通元素{

移除內容:對象.innerHTML="" / inner.Text=""

獲取內容:對象.innerHTML

}

表單元素{

移除,獲取,添加,都是value;

}

}

操作對象樣式

{

添加樣式,獲取:對象.style.width/height/backgroundColor

移除樣式: 對象.style = "";

實時獲取:offsetHeight

}

操作相關的樣式{

操作同輩元素{

上一個,下一個:註意空格和換行

}

}

操作相關的元素;

創建刪除元素;

事件;

正則表達式;

字符串,時間日期,數學函數;

其他;

}

js復習: