function setAllTextValuesTo(newText)
{ for (var i = 0; ; ++i) {
theElement = document.getElementById("set" + i); if (!theElement) { break;
} if (theElement.tagName == "INPUT" ||
theElement.tagName == "TEXTAREA") {
theElement.value = newText;
} else {
theElement.firstChild.textContent = newText;
}
}
}
function setAllTextDefaultValuesTo(newText)
{ for (var i = 0; ; ++i) {
theElement = document.getElementById("set" + i); if (!theElement) { break;
} if (theElement.tagName == "INPUT" ||
theElement.tagName == "TEXTAREA") {
theElement.defaultValue = newText;
} else {
theElement.firstChild.textContent = newText;
}
}
}
function setAllTextChildrenTo(newText)
{ for (var i = 0; ; ++i) {
theElement = document.getElementById("set" + i); if (!theElement) { break;
} if (theElement.tagName == "INPUT") {
theElement.value = newText;
} else {
theElement.firstChild.textContent = newText;
}
}
}
function appendTextFromArray(textArray)
{ for (var i = 0; ; ++i) {
theElement = document.getElementById("set" + i); if (!theElement) { break;
} for (var j = 0; j < textArray.length; ++j) { if (theElement.tagName == "INPUT") {
theElement.value += textArray[j];
} else { var textNode = document.createTextNode(textArray[j]);
theElement.appendChild(textNode);
}
}
}
}
// Add the members of the array to the text content of the elements in // the document, not including the last member. Then delete the last but // one and add the last one // Useful for testing scenarios like bug 1169267 function appendDeleteAppendTextFromArray(textArray)
{ if (textArray.length < 2) { return;
}
for (var i = 0; ; ++i) {
theElement = document.getElementById("set" + i); if (!theElement) { break;
} var isInput = (theElement.tagName == "INPUT"); if (!isInput) { var textNode = document.createTextNode("");
theElement.appendChild(textNode);
}
// delete the last element added var deleteElt = textArray[textArray.length - 2]; if (isInput) {
theElement.value = theElement.value.slice(0, -deleteElt.length);
} else {
textNode.deleteData(textNode.length - deleteElt.length,
deleteElt.length);
}
// add the next element var addElt = textArray[textArray.length - 1]; if (isInput) {
theElement.value += addElt;
} else {
textNode.appendData(addElt);
}
}
}
function appendSpansFromArray(textArray)
{ for (var i = 0; ; ++i) {
theElement = document.getElementById("set" + i); if (!theElement) { break;
} for (var j = 0; j < textArray.length; ++j) { // fake the result for elements that can't have markup content if (theElement.tagName == "INPUT") {
theElement.value += textArray[j];
} elseif (theElement.tagName == "TEXTAREA") {
theElement.innerHTML += textArray[j];
} else { var span = document.createElement("span");
span.innerHTML = textArray[j];
theElement.appendChild(span);
}
}
}
}
function prependTextFromArray(textArray)
{ for (var i = 0; ; ++i) {
theElement = document.getElementById("set" + i); if (!theElement) { break;
} for (var j = 0; j < textArray.length; ++j) { if (theElement.tagName == "INPUT") {
theElement.value = textArray[j] + theElement.value;
} else { var textNode = document.createTextNode(textArray[j]);
theElement.insertBefore(textNode, theElement.firstChild);
}
}
}
}
function prependSpansFromArray(textArray)
{ for (var i = 0; ; ++i) {
theElement = document.getElementById("set" + i); if (!theElement) { break;
} for (var j = 0; j < textArray.length; ++j) { // fake the result for elements that can't have markup content if (theElement.tagName == "INPUT") {
theElement.value = textArray[j] + theElement.value;
} elseif (theElement.tagName == "TEXTAREA") {
theElement.innerHTML = textArray[j] + theElement.innerHTML;
} else { var span = document.createElement("span");
span.innerHTML = textArray[j];
theElement.insertBefore(span, theElement.firstChild);
}
}
}
}
function removeElements()
{ for (var i = 0; ; ++i) {
theElement = document.getElementById("set" + i); if (!theElement) { break;
}
theElement.remove();
}
}
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.