我对 js 命名空间没有很好的掌握,并且我正在 WAGing* 重新命名,但这是我对正在发生的事情的猜测之一。
- WAG = 疯狂的猜测
我的应用程序崩溃(严重);试图找出原因。事实上,在 3 对 Q/A 之后,它炸毁了整个 Chrome 标签页..!我开始怀疑我的代码做错了什么......
警告:在运行这些 jsFiddles 之前保存您的浏览会话。(在 Chrome 中,jsFiddle 只会炸毁自己的标签,但我无法评论其他浏览器)
jsFiddle One
jsFiddle 二 - 欺骗以防 jsFiddle One 被吹走
请帮助我准确了解我今天犯了哪些惊人的白痴行为。
HTML:
<div id="result">
<div class="truth tr0"><h2>---</h2></div>
<div class="truth tr1"><h2>answer to one</h2></div>
<div class="truth tr2"><h2>answer to two</h2></div>
<div class="truth tr3"><h2>answer to three</h2></div>
<div class="truth tr4"><h2>answer to four</h2></div>
</div>
<div id="replaceLink">
<div class="youcould yc1">
<a href="#2"><h2>QUESTION ONE</h2></a>
</div>
<div class="youcould yc2">
<a href="#3"><h2>QUESTION TWO</h2></a>
</div>
<div class="youcould yc3">
<a href="#4"><h2>QUESTION THREE</h2></a>
</div>
<div class="youcould yc4">
<a href="#5"><h2>QUESTION FOUR</h2></a>
</div>
<div class="youcould yc5">
<a href="#6"><h2>THANK YOU</h2></a>
</div>
</div>
<div id="response"></div>
<input type="button" id="mybutt" value="Start Test" />
Javascript/jQuery:
var cnt = 0;
var window = {};
window.arrDone = [];
function nextQues() {
if (window.arrDone.length == 4) return 5;
success = 0;
while (success == 0) {
nn = Math.floor(Math.random() * 3) + 1;
if (window.arrDone.indexOf(nn) == -1 && nn != 5) {
success++;
window.arrDone.push(nn);
}
}
return nn;
}
$('.youcould, .truth').hide();
$('.tr0').show();
$('.youcould').click(function() {
$(this).hide();
thisA = window.arrDone[window.arrDone.length -1];
$('.tr'+thisA).show();
});
$('.truth').click(function() {
$(this).hide();
nextQ = nextQues();
$('.yc'+nextQ).show();
});
$('#mybutt').click(function () {
$(this).hide();
$('.tr0').hide();
nextQ = nextQues();
$('.yc'+nextQ).show();
});