Javascript无休止的循环没有明显的原因
当屏幕冻结时,我正在为我的网站开发搜索引擎。我假设有一个无止境的循环,但我没有发现任何验证服务上的错误。我能得到一些帮助吗Javascript无休止的循环没有明显的原因,javascript,html,loops,Javascript,Html,Loops,当屏幕冻结时,我正在为我的网站开发搜索引擎。我假设有一个无止境的循环,但我没有发现任何验证服务上的错误。我能得到一些帮助吗 <input id="Query" value="Type search here"></input> <input id="button" type="submit" name="button" value="Search"/> <script> var titles = ["Pacman", "Tu95", "Tank T
<input id="Query" value="Type search here"></input>
<input id="button" type="submit" name="button" value="Search"/>
<script>
var titles = ["Pacman", "Tu95", "Tank Trouble", "HTML", "Test", "Print", "Search"];
var links = ["http://www.mikeyrichards.co.vu/2015/03/pacman.html", "http://www.mikeyrichards.co.vu/p/tu95_23.html", "http://www.mikeyrichards.co.vu/p/tu95.html", "http://www.mikeyrichards.co.vu/2015/03/html-i-used-html-for-this-console.html", "http://www.mikeyrichards.co.vu/2015/03/test-post.html", "http://www.mikeyrichards.co.vu/2015/03/print-page.html", "http://www.mikeyrichards.co.vu/2015/03/search.html"];
var titleswork = [];
var titlesworknumbers = [];
document.getElementById('button').onclick = function() {
titleswork = [];
titlesworknumbers = [];
if (document.getElementById("results")) {
var clear = document.getElementById("results");
clear.parentNode.removeChild(clear);
}
var letterthroughdata = 0;
var data = document.getElementById("Query").value;
for (var i = 0; i < titles.length; i++) {
if (titles[i].length < data.length) {} else {
while (letterthroughdata < data.length) {
if (titles[i] === data[letterthroughdata]) {
letterthroughdata++;
}
}
if (letterthroughdata === data.length) {
titleswork.push(titles[i]);
titlesworknumbers.push(i);
}
}
}
};
console.log(titleswork);
console.log(titlesworknumbers);
var x = document.createElement("div");
x.setAttribute("id", "results");
for (var i = 0; i < titleswork.length; i++) {
var y = document.createTextNode(titleswork[i] + ": " + links[titlesworknumbers[i]]);
x.appendChild(y);
var brake = document.createElement("br");
x.appendChild(brake);
var z = document.getElementById("post-body-2820145598585075365");
}
z.appendChild(x);
</script>
var标题=[“Pacman”、“Tu95”、“坦克故障”、“HTML”、“测试”、“打印”、“搜索”];
变量链接=[”http://www.mikeyrichards.co.vu/2015/03/pacman.html", "http://www.mikeyrichards.co.vu/p/tu95_23.html", "http://www.mikeyrichards.co.vu/p/tu95.html", "http://www.mikeyrichards.co.vu/2015/03/html-i-used-html-for-this-console.html", "http://www.mikeyrichards.co.vu/2015/03/test-post.html", "http://www.mikeyrichards.co.vu/2015/03/print-page.html", "http://www.mikeyrichards.co.vu/2015/03/search.html"];
var titleswork=[];
var TitleWorkNumber=[];
document.getElementById('button')。onclick=function(){
标题工作=[];
TitleWorkNumber=[];
if(document.getElementById(“结果”)){
var clear=document.getElementById(“结果”);
clear.parentNode.removeChild(清除);
}
var letterthroughdata=0;
var data=document.getElementById(“查询”).value;
对于(变量i=0;i
这是一个无限循环:
while (letterthroughdata < data.length) {
if (titles[i] === data[letterthroughdata]) {
letterthroughdata++;
}
}
while(letterthroughdata
如果在任何情况下,
letterthroughdata
小于数据。长度和标题[i]
不等于数据[letterthroughdata]
,这将永远循环。有人能识别该代码吗?如果If语句为false,while循环将无限期循环。。