需要准备的材料分别有:电脑、html编辑器、浏览器。
1、首先,打开html编辑器,新建html文件,例如:index.html。
2、在index.html中的<script>标签,输入js代码:
var a = '2012-12-11'
var date1 = new Date(a.replace('-', '/'))
var t = date1.getTime() + 30 * 24 * 3600 * 1000
var date2 = new Date(t)
document.body.innerText = date2
3、浏览器运行index.html页面,此时打印出了2012-12-11加上30天的日期结果。
是<input type=text name = date" + i + "这个text的日期等于前一个的日期加1吗?
看代码:
<input type=text id=hidden value=0>
<table id="table1">
<TR>
<TD>
<DIV><INPUT ondblclick=addrowsother(this.value) name=date1 value="2001-1-21"></DIV></TD>
<TD>
<DIV><SELECT name=time1><OPTION selected value=上午>上午</OPTION><OPTION value=下午>下午</OPTION></SELECT></DIV></TD>
<TD>
<DIV><INPUT onclick=abc()name=richeng 1></DIV></TD>
<TD>
<DIV><INPUT name=partical 1></DIV></TD>
<TD>
<DIV><INPUT name=address 1></DIV></TD>
<TD>
<DIV><INPUT ondblclick=addrows()name=Zcr 1></DIV></TD></TR>
</table>
<SCRIPT LANGUAGE="JavaScript">
function addrowsother(val) {
var i = parseInt(document.getElementById("hidden").value)+1
var x = document.getElementById("table1").insertRow()
var h1 = x.insertCell(0)
var h2 = x.insertCell(1)
var h3 = x.insertCell(2)
var h4 = x.insertCell(3)
var h5 = x.insertCell(4)
var h6 = x.insertCell(5)
h1.innerHTML = "<div><input type=text name = date" + i + " ondblclick='addrowsother(this.value)' value='" + addday(val, 1) + "'></div>"
h2.innerHTML = "<div><select name=time" + i + " ><option value=上午>上午</option><option value=下午>下午</option></select></div>"
h3.innerHTML = "<div><input name=richeng " + i + " type=text onclick=abc()></div>"
h4.innerHTML = "<div ><input name=partical " + i + " type=text ></div>"
h5.innerHTML = "<div><input name=address " + i + " type=text ></div>"
h6.innerHTML = "<div><input name=Zcr " + i + " type=text ondblclick='addrows()'></div>"
// document.getElementById("date" + (i)).value = document.getElementById("date" + (i - 1)).value
document.getElementById("hidden").value = i
}
function addday(dt, days){
dt = dt.replace('-', '/')//js不认2000-1-31,只认2000/1/31
var t1 = new Date(new Date(dt).valueOf() + days*24*60*60*1000)// 日期加上指定的天数
return t1.getFullYear() + "-" + (t1.getMonth() + 1) + "-" + t1.getDate()
}
</SCRIPT>