11、網頁製作Dreamweaver(補充:JS零碎知識點&&Regex)

來源:互聯網
上載者:User

標籤:style   blog   http   ar   io   color   os   sp   for   

JS知識點

斷行符號符/r和分行符號/n的區別:/r 相當於enter,是段落與段落之間的區別,

             /n 相當於shift+enter,是行與行之間距離,比較小

幾種window操作方法:

1、擷取當前視窗大小並列印:

var height=window.innerHeight;var width = window.innerWidth;document.write("<br/>"+"height"+height+","+"width"+width);

2、開啟視窗、關閉當前視窗

window.open("http://baidu.com");window.close();

3、移動當前視窗到某一位置(x,y)

window.moveTo(200,200);

4、改變當前視窗的尺寸(width,height)

window.resizeTo(1100,1100);

5、擷取當前頁地址

document.write(location.href);

6、【記錄】網頁的前進(前進到之前的曆史,相當於“→”)、後退(後退到之前曆史,相當於“←”)

<!--後退用.back方法設定在另一個網頁中即可--><input type="button" onClick="a()"value ="點我前進"/>
function a()    {        window.history.forward();/*前進到之前的曆史*/    }

*navigator訪問者瀏覽器的資訊

alert:警告框 confirm:確認框 prompt:提示框

 

RegexRegExp:

建立Regex的方法:

var patten= new RegExp(/^[0-9]{17}[0-9|X]$/);/*RegExp()括弧裡面的式子需要自己定義:1、[]裡面只有一個元素2、()裡面可以寫一個單詞或者式子3、{}裡面表示數量
4、^:以某個元素開頭,寫在元素前面
5、$:以某個元素結束,寫在元素後面
*/

例:

1、Regex驗證身份證:

身份證:<input type="text" id="1"  />
/*javascript部分*/  var a= document.getElementById("1").value;  var patten= new RegExp(/^[0-9]{17}[0-9|X]$/);  if(patten.test(a))  {      alert("輸入正確");  }  else  {      alert("輸入錯誤");  }

2、Regex驗證郵箱:

郵箱:<input type="text" id="2" /><input type="button" value="提交" onclick="mail()" />
function mail(){    var patten2= new RegExp(/^[0-9|A-z|_]{1,17}[@][0-9|A-z]{1,3}.(com)$/)    var mail = document.getElementById("2").value;    if(patten2.test(mail))      {          alert("輸入正確");      }    else      {          alert("輸入錯誤");      }}

 

11、網頁製作Dreamweaver(補充:JS零碎知識點&&Regex)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.