<input id="text1" type="text" name="date" value="200901"/>
<input type="button" value="显示" onclick="showDate()"/>
<script>
function showDate(){
var str = document.getElementById("text1").value;
var req = /^(\d{4,})(\d\d)$/;
str = str.replace(req,"$1/$2/01");
var thedate = new Date(str); var str2 = (thedate.getMonth() + 1) < 10 ? ("0" + (thedate.getMonth() + 1)) : ("" + (thedate.getMonth() + 1));
alert("当前" + thedate.getFullYear() + str2); thedate.setMonth(thedate.getMonth() - 1);
str2 = (thedate.getMonth() + 1) < 10 ? ("0" + (thedate.getMonth() + 1)) : ("" + (thedate.getMonth() + 1));
alert("上一月" + thedate.getFullYear() + str2);
}
</script>