Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
一次调用2个javascript函数时html中的问题_Javascript_Html_Function_Types - Fatal编程技术网

一次调用2个javascript函数时html中的问题

一次调用2个javascript函数时html中的问题,javascript,html,function,types,Javascript,Html,Function,Types,我有一个与javascript文件相关的HTML文件。 在这个javascript文件中,我有3个函数,其中2个函数将被称为onload of the body。 这两个函数用于键入字符串,每个函数位于不同的文本区域。 但是,在测试时,这些js函数键入的两个字符串是不可读的 为了澄清我的问题:字符串必须如下所示: verification step 3 of 4 passed… enter serial number 当我调用body的onload这两个函数时,它给出了以下结果: vrfcto

我有一个与javascript文件相关的HTML文件。 在这个javascript文件中,我有3个函数,其中2个函数将被称为onload of the body。 这两个函数用于键入字符串,每个函数位于不同的文本区域。 但是,在测试时,这些js函数键入的两个字符串是不可读的 为了澄清我的问题:字符串必须如下所示:

verification step 3 of 4 passed…
enter serial number
当我调用body的onload这两个函数时,它给出了以下结果:

vrfcto  f4pse..
ne eilnme..
我在代码中找不到问题

HTML代码


请注意,当我分开调用这两个函数中的一个时,它可以工作。

我可能错了,但我认为问题在于索引。每种类型都有相同的变量名,当它们同时运行时,会混淆脚本。您有一个名为index的变量,它将+=1,因此当下一个函数得到它时,它就乱七八糟了


尝试将type2上索引的变量更改为index2。看看这是否解决了问题。

您已经两次尝试声明变量索引。尝试在第二个函数中重命名它,它应该可以正常工作

说明:
您声明var index=0;在同一范围内两次。在本例中,使用的是第二个声明,因此函数中只有索引变量。这就是为什么每个函数都会显示每一个字母

更改第2行中索引的名称function@Sionnach733非常感谢!!:是的,将索引改为Indexorry很有效,但我做不到。因为Sionnach733在你面前给了我问题的解决方案,即使是在评论中。所以我必须尊重他,我明白。他加上的时候我正在打字,因为这不是答案,所以在我打字时没有提醒我这是答案。没有注意到上面的快速评论。点的占位符。。。哈哈,鬼鬼祟祟。很简单,你说服了我p@WreithKassan我先发表评论,以防出现其他潜在问题。索引问题对我来说是显而易见的,但可能还有更多。你用我可能错的话打开了你的答案。当我发帖的时候我很确定。。
<!DOCTYPE HTML>
<html>
<head>
  <title>Webmaster's Top Secret Directory</title>
  <link rel="stylesheet" href="index.css">
  <script src="redirector5.js"></script>
</head>
<body background="camouflage.jpg" onload='write()'>
  <div align="center">

     <img src="header.png" alt="Warning"/>

  </div><br><br><br><br><br><br>
  <div id="container">
     <form name="form1" onsubmit="return myFunction();">
        <div><table align="center" class="table">
<tr><td>
<input type="text" class="inputtext2" name="text" value="open sesame" disabled /></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" value="identify yourself...." disabled /></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" value="omar saab" disabled /></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" value="verification step 1 of 4 passed....  enter secret phrase...." disabled /></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" value="i own you terminal. release security now and let me in" disabled /></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" value="verifying.... verification step 2 of 4 passed.... enter your purpose of entrance...." disabled /></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" value="manage personal files" disabled /></td>
</tr>
<tr>
<td><textarea class="inputtext2222" id='screen' disabled></textarea></td>
</tr> 
<tr>
<td><textarea class="inputtext2222" id='screen2' disabled></textarea></td>
</tr> 

<tr>
<td><input type="text" class="inputtext2" id="myTextarea" autofocus spellcheck="false" /></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" disabled/></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" disabled/></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" disabled/></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" disabled/></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" disabled/></td>
</tr>
<tr>
<td><input type="text" class="inputtext2" disabled/></td>
</tr>



</table>
        </div>
        <input 
           type="submit" 
           name="submit">
     </form>
  </div>
</body>
</html>
function myFunction() {
var x = document.getElementById("myTextarea").value;
if (x === "tango-whisky-70433863") {
  document.location.href = "index6.html";
  return false;
}
else {
  alert('Command not found.\nYou are not supposed to be here.\nGet out now !');
  return false;
}
}

function write(){
type();
type2();
}

var index = 0;
var text = 'verification 3 of 4 passed...';
function type()
{
document.getElementById('screen').innerHTML += text.charAt(index);
index += 1;
var t = setTimeout('type()',80);
}

var index = 0;
var text2 = 'enter serial number....';
function type2()
{
document.getElementById('screen2').innerHTML += text2.charAt(index);
index += 1;
var t = setTimeout('type2()',80);
}