javascript - 为什么 JS 每个函数只运行一次 document.Tastierino.Testo.value?
问题描述
我是 Javascript 的初学者,我想编写一个迷你游戏,我编写了所有代码并且它可以工作,除了代码似乎跳过第 56 行的小点,问题不在于有问题的行,因为如果我删除下一个两条线它工作。你能告诉我错误在哪里吗?
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body style="background-color: #4F4F4F">
<p>Guess the number
<center>
<form name="Tastierino">
<table>
<tr><td colspan="3"><textarea cols="17" rows="2" value="" name="Testo" readonly></textarea></td></tr>
<tr>
<td><center><input type="button" value=" 7 " onClick="aggiungi('7')"></center></td>
<td><center><input type="button" value=" 8 " onClick="aggiungi('8')"></center></td>
<td><center><input type="button" value=" 9 " onClick="aggiungi('9')"></center></td>
</tr>
<tr>
<td><center><input type="button" value=" 4 " onClick="aggiungi('4')"></center></td>
<td><center><input type="button" value=" 5 " onClick="aggiungi('5')"></center></td>
<td><center><input type="button" value=" 6 " onClick="aggiungi('6')"></center></td>
</tr>
<tr>
<td><center><input type="button" value=" 1 " onClick="aggiungi('1')"></center></td>
<td><center><input type="button" value=" 2 " onClick="aggiungi('2')"></center></td>
<td><center><input type="button" value=" 3 " onClick="aggiungi('3')"></center></td>
</tr>
<tr>
<td></td>
<td><center><input type="button" value=" 0 " onClick="aggiungi('0')"></center></td>
<td></td>
</tr>
<tr><td colspan="3"><center><input type="button" value=" Conferma " onClick="conferma()"></center></td></tr>
</table></form>
<script language="Javascript">
var Nrand=(Math.floor((Math.random() * 30) + 1));
var errori=0;
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
};
};
};
function aggiungi(n) {
document.Tastierino.Testo.value=document.Tastierino.Testo.value+n;
};
function conferma(){
var Nscelto=document.Tastierino.Testo.value;
if(Nscelto==Nrand){
document.Tastierino.Testo.value="bravo hai vinto!";
}else{
if(Nscelto<Nrand){
document.Tastierino.Testo.value="è sbagliato il numero è maggiore";
sleep(2000);
document.Tastierino.Testo.value="";
}else{
document.Tastierino.Testo.value="è sbagliato il numero è minore";
sleep(2000);
document.Tastierino.Testo.value="";
}}};
</script>
</center>
</p>
</body>
</html>
解决方案
推荐阅读
- python - Tensorflow:使用 tf.where() 时如何保持批量维度?
- c# - Firefox 在新选项卡中打印 pdf 不起作用
- regex - 熊猫提取正则表达式允许不匹配
- google-apps-script - 当一行中的单元格值更改为更改单元格的同一行中的电子邮件地址时发送电子邮件
- java - 在 hashmap 中,向桶的内部链表添加新元素总是在最后。为什么?
- javascript - 在 javascript 中更新 vuejs 列表项
- c# - RabbitMQ 将消息标记为死信
- visual-studio - 使用 Visual Studio 2019 Vers.16.2.5 构建 Uno 平台解决方案的问题
- python - 使用 for 循环创建数据框后创建 Pandas 数据框列表
- html - 我的网页无法在 IE 和 Firefox 中运行