var length = testData.length;
for (var i=0; i<length; ++i) {
for (var j=0; j<length; ++j) { var e = document.createElement('input');
e.type = testData[i][0];
var expectedValue;
// range will sanitize its value to 50 (the default) if it isn't a valid
// number. We need to handle that specially.
if (testData[j][0] == 'range' || testData[i][0] == 'range') {
if (testData[j][0] == 'date' || testData[j][0] == 'time' ||
testData[j][0] == 'month' || testData[j][0] == 'week' ||
testData[j][0] == 'datetime-local') {
expectedValue = '';
} else if (testData[j][0] == 'color') {
expectedValue = '#000000';
} else {
expectedValue = '50';
}
} else if (testData[i][0] == 'color' || testData[j][0] == 'color') {
if (testData[j][0] == 'number' || testData[j][0] == 'date' ||
testData[j][0] == 'time' || testData[j][0] == 'month' ||
testData[j][0] == 'week' || testData[j][0] == 'datetime-local') {
expectedValue = ''
} else {
expectedValue = '#000000';
}
} else if (nonTrivialSanitizing.includes(testData[i][0]) &&
nonTrivialSanitizing.includes(testData[j][0])) {
expectedValue = '';
} else if (testData[i][0] == 'number' || testData[j][0] == 'number') {
expectedValue = '42';
} else if (testData[i][0] == 'date' || testData[j][0] == 'date') {
expectedValue = '2012-12-21';
} else if (testData[i][0] == 'time' || testData[j][0] == 'time') {
expectedValue = '21:21';
} else if (testData[i][0] == 'month' || testData[j][0] == 'month') {
expectedValue = '2013-03';
} else if (testData[i][0] == 'week' || testData[j][0] == 'week') {
expectedValue = '2016-W35';
} else if (testData[i][0] == 'datetime-local' ||
testData[j][0] == 'datetime-local') {
expectedValue = '2016-11-07T16:40';
} else {
expectedValue = "foo";
}
e.value = expectedValue;
e.type = testData[j][0];
is(e.value, expectedValue, ".value should still return the same value after " + "changing type from " + testData[i][0] + " to " + testData[j][0]);
}
}
// For type='file' .value doesn't behave the same way.
// We are just going to check that we do not loose the value.
for (var data of testData) { var e = document.createElement('input');
e.type = data[0];
e.value = 'foo';
e.type = 'file';
e.type = data[0];
if (data[0] == 'range') {
is(e.value, '50', ".value should still return the same value after " + "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
} else if (data[0] == 'color') {
is(e.value, '#000000', ".value should have been reset to the default color after "+ "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
} else if (data[1]) {
is(e.value, '', ".value should have been reset to the empty string after " + "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
} else {
is(e.value, 'foo', ".value should still return the same value after " + "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.