截取字符串:
- var str = "1234567890";
- var a = str.substring(0,8); //==str.substring(8)---结果:12345678
显示当前期系统时间:
- 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
从文本框得到的数值计算:
- var shu1 = document.getElementById("shu1").value; //----2
- var shu2 = document.getElementById("shu2").value;//----5
- var sum = parseInt(shu1) + parseInt(shu2); //要把得到文本框的值转成int,再加,否则直接加,会当成字符串,进行连接为25
本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/819702