取得页面上一个文本框控件txtdate的值
答案:1 悬赏:20 手机版
解决时间 2021-11-19 02:21
- 提问者网友:富士山上尢
- 2021-11-18 02:42
取得页面上一个文本框控件txtdate的值
最佳答案
- 五星知识达人网友:不如潦草
- 2021-11-18 02:56
先把文本框A的值转为Date对象,对Date对象操作后将其转为字符串,再传给B
function changeDate() {
var offset = 10;
var dateStrA = txtA.value;
var year = dateStrA.substring(0,4);
var month = Number(dateStrA.substring(5,7))-1;
var date = Number(dateStrA.substring(8,10))+offset;
var dateB = new Date();
dateB.setFullYear(year,month,date);
var year2 = dateB.getFullYear();
var month2 = (dateB.getMonth()+1)+"";
var date2 = dateB.getDate()+"";
if (month2.length == 1) month2 = "0"+month2;
if (date2.length == 1) date2 = "0"+date2;
txtB.value = year2 + "-" + month2 + "-" + date2;
}
function changeDate() {
var offset = 10;
var dateStrA = txtA.value;
var year = dateStrA.substring(0,4);
var month = Number(dateStrA.substring(5,7))-1;
var date = Number(dateStrA.substring(8,10))+offset;
var dateB = new Date();
dateB.setFullYear(year,month,date);
var year2 = dateB.getFullYear();
var month2 = (dateB.getMonth()+1)+"";
var date2 = dateB.getDate()+"";
if (month2.length == 1) month2 = "0"+month2;
if (date2.length == 1) date2 = "0"+date2;
txtB.value = year2 + "-" + month2 + "-" + date2;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯