截取字符串:this
- var str = "1234567890";
- var a = str.substring(0,8);
var str = "1234567890";
var a = str.substring(0,8); //==str.substring(8)---結果:12345678
顯示當前期系統時間:url
- var today = new Date();
- var day = today.getDate();
- var month = today.getMonth() + 1;
- var year = today.getYear();
- month = month<10?"0"+month:month;
- day = day<10?"0"+day:day;
- var date = year + "-" + month + "-" + day;
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1; //顯示月份比實際月份小1,因此要加1
var year = today.getYear();
month = month<10?"0"+month:month; //數字<10,實際顯示爲,如5,要改爲05
day = day<10?"0"+day:day; //和月份顯示同樣
var date = year + "-" + month + "-" + day; //結果:2008-05-08,2008-12-29
從文本框獲得的數值計算:spa
- var shu1 = document.getElementById("shu1").value;
- var shu2 = document.getElementById("shu2").value;
- var sum = parseInt(shu1) + parseInt(shu2);
本文出自 「阿凡達」 博客,請務必保留此出處http://shamrock.blog.51cto.com/2079212/819702code