2014-10-09 71 views
1
alert(parseInt(new Date().toLocaleString('es', {month:'numeric'}))); 

此代碼總是返回 '男' 在IE通過parseInt函數()和的toLocaleString Internet Explorer中返回NaN在解析時價值

這是爲什麼?

我該如何解決只使用香草JavaScript。

+0

你究竟想幹什麼? – Sirko 2014-10-09 18:19:58

+0

只有現代瀏覽器(包括IE11)支持語言環境和選項參數,https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString – undefined 2014-10-09 18:20:24

+0

哪個版本的IE?您確定該通話與您使用的IE版本兼容嗎? – 2014-10-09 18:20:27

回答

3
var date = new Date(); 
var month = date.getMonth() + 1; //Months are zero based 

這應該爲你工作得到月份。