gpt4 book ai didi

JavaScript 重新分配值不起作用

转载 作者:行者123 更新时间:2023-12-01 00:34:54 25 4
gpt4 key购买 nike

当我尝试将输入框的值重新分配给 JavaScript 中的不同值时,没有任何变化。我已发出警报以确保变量有效,并且我还尝试添加 toString() 方法。

function assignWords(){
alert("word one " + wordOne);
document.getElementById("word1").value = wordOne;
document.getElementById("word2").value = wordTwo.toString();
document.getElementById("word3").value = wordThree.toString();
document.getElementById("word4").value = wordFour.toString();
document.getElementById("word5").value = wordFive.toString();
}
<div class="PlayGame"> 
<h2>Word Scramble USA</h2>
<input id="myText" type="text" placeholder="begin to type" onkeyup="checkWords()" />
<input id="word1" type="submit" name="word1" value="">
<input id="word2" type="submit" name="word2" value="" disabled>
<input id="word3" type="submit" name="word3" value="" disabled>
<input id="word4" type="submit" name="word4" value="" disabled>
<input id="word5" type="submit" name="word5" value="" disabled>
</div>

最佳答案

你应该调用你的函数

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<div class="PlayGame">
<h2>Word Scramble USA</h2>
<input
id="myText"
type="text"
placeholder="begin to type"
onkeyup="checkWords()"
/>
<input id="word1" type="submit" name="word1" value="" />
<input id="word2" type="submit" name="word2" value="" disabled />
<input id="word3" type="submit" name="word3" value="" disabled />
<input id="word4" type="submit" name="word4" value="" disabled />
<input id="word5" type="submit" name="word5" value="" disabled />
</div>
</body>
<script>
function assignWords() {
document.getElementById("word1").value = "Need";
document.getElementById("word2").value = "for";
document.getElementById("word3").value = "function";
document.getElementById("word4").value = "call";
document.getElementById("word5").value = wordFive.toString();
}
assignWords();
</script>
</html>

关于JavaScript 重新分配值不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58211515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com