發(fā)現(xiàn)個(gè)小細(xì)節(jié)問題,望解答
現(xiàn)在是8月份,然后下面兩行代碼在輸出"月份數(shù)+1"時(shí),第一行代碼輸出8,第二行行輸出71(沒有進(jìn)行加法),請(qǐng)問是為什么?然后第二行要怎么改月份數(shù)才能輸出8
document.write(mydate.getMonth()+1);
document.write(mydate.getFullYear()+"年"+mydate.getMonth()+1+"月"+mydate.getDate()+"日"+" "+myday[mydate.getDay()]+"--");
2017-08-29
因?yàn)椤?“起的是字符串拼接的作用,所以會(huì)出現(xiàn)71,加個(gè)括號(hào)就行,document.write(mydate.getFullYear()+"年"+(mydate.getMonth()+1)+"月");
2017-08-29
mydate.getMonth()+1外面要加括號(hào)