javascript 函數,事件

來源:互聯網
上載者:User

標籤:沒有   ase   hello   ...   頁面   upper   new   length   bubble   

1、函數
字串函數

var s=new string();

var ss="hello world";

var sss=""HELLO, WORLD";

alert(ss.toLowerCase());——轉換成小寫

alert(sss.toUpperCase());——轉換成大寫

alert(ss.substr(2,3));——截取字串,從索引2開始,截取3個字元長度,不寫後面的數字是截到最後

alert(ss.substring(2,3));——截取字串,從第2個位置截取到第3個位置

sss.splite(",");——將字串按照指定的字元分開

ss.length屬性,字串長度

ss.indexof("world");——尋找world在字串中第一次出現的位置,沒有的話返回-1

ss.lastIndexof("o");——尋找o在字串中最後一次出現的位置

時間日期函數

var d=new Date();——目前時間

var dd=new Date(1999,3,2);——定義時間

dd.getFullYear();——取年份

dd.getMonth();——取月份,取出來的少1

dd.getDate();——取日期

dd.getDay();——取星期幾

...

dd.setFullYear();——設定年份,設定月份的時候注意+1

數學函數

math.ceil();——取上限

math.floor();——取下限

math.sqrt();——開平方

math.round();——四捨五入

math.random();——隨機數,0-1之間

2、全部事件
onclick ——單擊事件
ondblclick——雙擊事件

onmouseover——滑鼠移入
onmouseout——滑鼠移除

onfocus——擷取焦點
onblur——失去焦點

onkeyup——按鍵抬起時觸發

window.onload——按鍵按下時觸發

window.onresize——尺寸改變時觸發

window.onload——頁面載入完觸發


3、補充


阻止事件冒泡:
window.event ? window.event.cancelBubble = true : e.stopPropagation();

javascript 函數,事件

聯繫我們

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