js基本知識點回顧

來源:互聯網
上載者:User

標籤: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基本知識點回顧

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.