function AlertMailNum() { var colors = new Array("red", "orange", "yellow", "green", "cyan", "blue", "purple"); var colorStartIndex = 0; setBreathLightOn(colors, colorStartIndex); } function setBreathLightOn(colors, colorIndex) { var mailNum = $("input[id$='MailNum']").val(); if (mailNum > 0) { var mailMappingButton = $("[id$='MailMappingLinkButton']"); colorIndex = colorIndex % 7; mailMappingButton.animate( { color: colors[colorIndex] }, 2000, "swing", setBreathLightOn(colors, colorIndex + 1)); } else { var mailMappingButton = $("#Header_MailMappingLinkButton"); mailMappingButton.removeAttr("style"); } }
SCRIPT28: Out of stack space
Tracking.js (243,5)
你这个递归操作会出现死循环了
是的,谢谢啦。今天上午脑子有点乱,这么明显居然没看出来
function setBreathLightOn(colors, colorIndex) { var mailNum = $("input[id$='MailNum']").val(); if (mailNum > 0) { var mailMappingButton = $("[id$='MailMappingLinkButton']"); colorIndex = colorIndex % 7; mailMappingButton.animate( { color: colors[colorIndex] }, 2000, "swing", function () { if (mailNum > 0) { setBreathLightOn(colors, colorIndex + 1); } else { mailMappingButton.removeAttr("style"); } }); } }
使用递归时犯的低级错误。代码进入死循环了。应该有循环出口。