這也發生在IE11上。我遇到了同樣的問題,通過使用下面的日期來修復它,這樣你就不會看到任何看不見的空字符。
var cleanDate = (new Date()).toISOString();
這是針對您的問題的解決方案,如果您不想使用上述獲取日期的方法。
//Custom extension method to replace all found value.
String.prototype.replaceAll = function(find, replace) {
var target = this;
return target.split(find).join(replace);
};
//Find there is invisible empty character
var emptyCode = (new Date()).toLocaleString().charCodeAt(0);
var cleanDate = undefined;
if(emptyCode === 8206)
{
//Remove all invisiable empty characters
cleanDate =(new Date()).toLocaleString().replaceAll(String.fromCharCode(emptyCode),'');
}
擴展方法可以從下面的文章中找到。 How to replace all occurrences of a string in JavaScript?
'的console.log(新的日期()的toLocaleString()分裂( 「」)地圖(函數(C){返回c.charCodeAt(0);}))' – Pointy
此外,適用什麼樣的語言環境到你正在做的測試? – Pointy
en-US(更新後的問題) –