简体   繁体   English

简单的 JS 执行但不做任何事情

[英]Simple JS executes but doesn't do anything

I have a simple web page like so:我有一个简单的网页,如下所示:

 /*global define*/ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50*/ /*global $ */ $(function alap() { "use strict"; var TEST_BOXCOUNT = 5; function Tile(name, date, time, description) { this.name = name; this.date = date; this.time = time; this.description = description; } $('#boxCount').on('input', function(event) { var boxCount = Number(event.target.value); var boxContainer = $('#boxContainer'); boxContainer.empty(); console.log("so far so good"); for (var i = 1; i <= boxCount; i++) { console.log("in loop"); var box = $('<div>').addClass('box'); boxContainer.append(box); } }) });
 #controls>label { display: block; } #boxes { margin-top: 10px; } .box { height: 20px; margin: 5px; width: 20px; background-color: blue; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="controls"> <label for="boxCount">Box count?</label> <input type="text" id="boxCount"> </div> <div id="boxContainer"></div>

The intention is to drop down some boxes as tiles, the quantity is the input value.目的是将一些框作为瓷砖下拉,数量是输入值。 I have those logs input, and actually they execute , I see the appropriate count of log calls.我有这些日志输入,实际上它们执行,我看到log调用的适当计数。 The problem is that nothing appears.问题是什么都没有出现。

It is strange that the exact same code worked when using in JSFiddle , but unsure why no boxes show up here.奇怪的是,在JSFiddle使用时完全相同的代码可以工作,但不确定为什么这里没有显示框。 I request assistance to sort this out.我请求帮助来解决这个问题。

EDIT:编辑:

As you see, I have a TEST_BOXCOUNT and a Prototype definition in place.如您所见,我有一个TEST_BOXCOUNT和一个Prototype定义。 I'm not using them right now, but later on I'll make these boxes clickable with some info on them.我现在不使用它们,但稍后我会让这些框可以点击,并提供一些关于它们的信息。 They aren't supposed to do anything in this case though.不过,在这种情况下,他们不应该做任何事情。

What it logs:它记录了什么:

alap.js:20 so far so good alap.js:20 到目前为止一切顺利

alap.js:22 in loop alap.js:22 循环

alap.js:20 so far so good alap.js:20 到目前为止一切顺利

12 alap.js:22 in loop 12 alap.js:22 循环

There's really nothing else to say.真的没什么好说的了。 I just copy pasted all my stuff to a new folder and it works like a charm.我只是将我所有的东西复制粘贴到一个新文件夹中,它就像一个魅力。

The only thing I can think of is, that my old project was in my OneDrive folder, and it may be protected (against viruses to execute), or because of my slow net connection it timed out.我唯一能想到的是,我的旧项目在我的OneDrive文件夹中,它可能受到保护(防止病毒执行),或者因为我的网络连接速度慢而超时。 These are just hypotheses, I really have no clue why it works, but it works.这些只是假设,我真的不知道它为什么有效,但它有效。

So again, move you project to anywhere that's not in a cloud saver folder, and it might solve the issue.因此,再次将您的项目移动到不在云保护程序文件夹中的任何位置,它可能会解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM