我有HTML细分:
<select id="myList">
<option value="1"selected="selected">Position 1</option>
<option value="2">Position 2</option>
<option value="3">Position 3</option>
<option value="4">Position 4</option>
<option value="5">Position 5</option>
</select>
<input type="submit" id="go" value="Go to Position"></input>
提示用户选择聚光灯的位置。 JS方面包含:
var select = document.getElementById("myList");
var answer = select.options[select.selectedIndex].value;
if (answer == "1") {
document.getElementById("go").onclick = function () { ightAtX = -1.0; lightAtZ = 0.5; };
} else if (answer == "2") {
document.getElementById("go").onclick = function () { lightAtX = -1.0; lightAtZ = -0.5; };
} else if (answer == "3") {
document.getElementById("go").onclick = function () { lightAtX = 0.0; lightAtZ = -0.5; };
} else if (answer == "4") {
document.getElementById("go").onclick = function () { lightAtX = 1.0; lightAtZ = -0.5; };
} else if (answer == "5") {
document.getElementById("go").onclick = function () { lightAtX = 1.0; lightAtZ = 0.5; };
} else {
return;
}
我希望用户点击“转到位置”&#39;按钮以改变聚光灯的位置。但是,当我单击按钮时,没有任何变化。我错过了什么?
答案 0 :(得分:2)
您需要检查onclick函数内的选择(答案)。答案评估一次(除非没有包含更多代码),除非你告诉它,否则不会动态更新。
这样的事情:
import random
Names = ['AETHER', 'BADGED', 'BALDER', 'BANDED', 'BANTER', 'BARBER', 'BASHER'] #ect, etc
def wordlist(words):
for index, item in enumerate(words):
print(index, ") ", item, sep='')
available_words = random.sample(Names, 8)
one = random.choice(available_words)
print("Welcome to the Guess-The-Word Game.\nThe Password is one of these words:")
wordlist(available_words)
def Main():
remainingGuess = 4
while remainingGuess > 0 and False:
wordlist(available_words)
print("Guesses remaining: ", remainingGuess)
userNum = int(input("Enter guess number between 0-7: "))
print(userNum)
if wordlist[userNum] == one:
win = True
print("You are Correct")
else:
print("You incorrect")
remainingGuess -=1
if win == True
break