我有一個奇怪的問題,我的功能正常工作(一個jQuery掃描發生器),但它不顯示輸出,除非我按下後退按鈕在瀏覽器上。該代碼是:jQuery結果沒有顯示,除非我按'後退'按鈕
$(document).ready(function() {
$("input[name=Submit]").click(function() {
var x = $("input[name=playerNumber]").val();
var y = $("input[name=teamNumber]").val();
var playerArray = new Array(x);
var teamArray = new Array(y);
var areaToAddTo = $('#playerArea');
for (var i = 0; i < x; i++) {
playerArray[i] = prompt("What is the name of player "+(i+1)+"?");
}
for (var j = 0; j < y; j++) {
teamArray[j] = prompt("What is the name of team "+(j+1)+"?");
}
var teamsToLeaveOut = teamArray.length % playerArray.length;
var count = 0;
var randomNumber;
while (count < teamsToLeaveOut) {
randomNumber = Math.floor(Math.random()*(teamArray.length));
teamArray.splice(randomNumber, 1);
count++;
}
count = teamArray.length;
var spliceTeam;
var l;
while (count > 0) {
for (i = 0; i < playerArray.length; i++) {
randomNumber = Math.floor(Math.random()*teamArray.length);
spliceTeam = teamArray[randomNumber];
l += ('<h3>'+playerArray[i]+'</h3>');
l += ('<p>'+spliceTeam+'</p>');
teamArray.splice(randomNumber,1);
count--;
}
}
if (1 == 1) {
areaToAddTo.append(l);
}
});
});
在運行功能沒有數據被寫入到屏幕上,瀏覽器網址是: /sweepstake.html?playerNumber=2&teamNumber=5&Submit=Submit
在按下後退按鈕的輸出是理所應當的,瀏覽器網址是: /sweepstake.html
有關如何解決此問題的任何建議?
謝謝。
'if(1 == 1)'?? – jbrtrnd
'input [name = Submit]'是一個實際的提交按鈕嗎?如果是這樣,看起來你實際上發佈了你的表格,當你不想。您可以'返回false'來防止默認操作(在這種情況下,處理點擊按鈕)並停止傳播(從而防止事件冒泡DOM)。 –
@JBRTRND嗯,有一些特殊情況,當1不等於1.就像1重新定義時一樣。 – raina77ow