Mysterious (für mich) "Objekt unterstützt diesen Properenz- oder Methodenfehler nicht - JavaScript HTML -Rollout
-
27-10-2019 - |
Frage
Ich erhalte den Fehler oben aus Char 1 der 4. Zeile ... keine Ahnung, was ihn wirft? Ich bin sicher, es ist etwas Einfaches, das ich nicht sehe ...
out = out + "<b>Select Box Information</b><br><br> The name of the select box is: skeletor. A play on the word selector.<br>"
out = out + "The options for the select box are, Default Value, Option 2, Option 3, Option 4 and Option 5.<br>"
out = out + "The values for each option, from top to bottom, are: " + lucy.skeletor.option(0) + ", "
out = out + lucy.skeletor.option(1) + ", " + lucy.skeletor.option(2) + ", " + lucy.skeletor.option(3)
out = out + ", " + lucy.skeletor.option(4) + ".<br><br>"
out = out + "The index of the first option in the select box is: 0. The location of the user-selected option is: " + lucy.skeletor.value + ".<br><br>"
Lösung
Ich würde denken lucy.skeletor.option(1)
wird hier das Problem sein. Wenn lucy.skeletor
ist echt select
Element, es enthält eine options
Array. Auf dieses Array kann verwiesen werden wie: lucy.skeletor.options[n]
Wenn Sie verkettet, könnten Sie außerdem tun:
out += somestring+someotherstring+morestrings ... etc
Andere Tipps
out = out + ... ist in Ordnung, einfach nicht notwendig. Ihr Problem besteht darin
Wenn der Skeletor eine dann die richtige Syntax für neuere Browser ist, ist
lucy.options [1] .Value oder .text
Hier ist, was ich denke, du meinst du
var out = "";
out += "<b>Select Box Information</b><br><br> The name of the select box is: skeletor. A play on the word selector.<br>"
out += "The options for the select box are, Default Value, Option 2, Option 3, Option 4 and Option 5.<br>"
out += "The values for each option, from top to bottom, are: "
var opts=[];
for (var i=0;i<lucy.skeletor.options.length;i++) opts.push(lucy.skeletor.options[0].text);
out += opts.join(", ");
out += ".<br><br>"
out += "The index of the first option in the select box is: 0. The location of the user-selected option is: " + lucy.skeletor.value + ".<br><br>"
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow