我能够从链接的 StackOverflow 主题中调整测试以测试键:
function run_test(lowerlimit, UPPERLIMIT) {
try {
if (!window.localStorage) {
// I recall that in one of the older Chrome version (4),
// localStorage === null
return 'Localstorage is not supported';
}
if (isNaN(lowerlimit) || isNaN(UPPERLIMIT) || lowerlimit > UPPERLIMIT) {
return 'One of the limits is not a valid number!';
}
var i = lowerlimit - 1;
var character_range = [];
while (++i < UPPERLIMIT) character_range.push(i);
input = String.fromCharCode.apply(String, character_range);
localStorage.setItem(input, input);
output = localStorage.getItem(input);
if (input === output) {
return true;
}
// Uh oh, not equal!
var result = [];
for (i=0; i<UPPERLIMIT-lowerlimit; i++) {
if (input[i] !== output[i]) {
result.push(i + lowerlimit);
}
}
return result;
}catch(e){return 'Error:' + e;}
}
run_test(0x20, 0xD7FF);
结果似乎是一样的,至少在 Chrome 中是这样。还需要在其他浏览器中测试。