日期:2014-05-16  浏览次数:20492 次

一段js代碼,感覺判斷條件縱使為真。
當系統時間是2007年5月10日。
函數依舊回執行到alert( "123 ") 。
感覺if   (showMonth=1)總是為true.
var   lastDate   =   new   Date();
//var   teshu   date
var   showMonth=lastDate.getMonth()   +   1  
alert( "showMonth= "   +   showMonth)
alert(lastDate.getMonth())
if   (showMonth=1)
{
alert( "123 ")
lastDate.setYear(lastDate.getYear()   -   1)  
lastDate.setMonth(11)

}
else
{
alert( "ddd ")
lastDate.setMonth(lastDate.getMonth())
}

------解决方案--------------------
if (showMonth=1) ==> if (showMonth == 1)
------解决方案--------------------
showMonth=1
改成
showMonth==1