標籤:script asc tin ref win 函數 dom 擷取對象 out
JavaScript: 基本文法: 與c#文法基本一致,類型轉換:var a= parseint(值): var b = parsefloat(值);
isNaN(值):判斷是否是數字,是返回false不是返回true;
函數方法:
//有傳回值: <script > var ccc = test1(5,6); alert(ccc); function test1(a,b){ var c = a+b; renturn c;} </script>
// 無傳回值 <script > test1(); function test1(){ alert(‘hello word‘);} </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對象:
擷取對象:
<script> document.getElementById("id") document.getElementsByClassName("class") document.getElementsByName("name") document.getElementsByTagName("標記")</script>
操作對象屬性:
添加屬性:對象.setAttribute("name","value");
移除屬性:對象.removeAttribute("name");
擷取屬性值:對象.getAttribute("name");
操作對象內容:
對象.innerHTML=“” /對象.innerText ="";
innerHTML會將裡面寫的有關的代碼編譯出來而Text會將你寫的內容當做文本展示出來並不會編譯。
普通元素:
移除內容:對象.innerHTML="" / inner.Text=""
擷取內容:對象.innerHTML
js基本知識點回顧