
[英]Asynchronous recursive JavaScript function returns same value and terminates abruptly
[英]JavaScript abruptly returns or exits
当调用下面的JavaScript方法时,将显示第一个警报。 甚至没有打印“返回之前”警报。 仅当我执行F12时,才会显示其他警报。 请提出建议!
function validateFPNotes() {
var message = "";
var notesId = document.getElementById('FANManagementForm:FANNotesTextIp');
alert("validateFPNotes called and the notesid is :" + notesId);
if (notesId != null) {
alert("Not Null Block");
var notesVal = trimString(notesId.value);
alert("Notes Val:" + notesVal);
window.console.log("validateFPNotes::notesId.value = " + notesId.value);
alert("doc.getEletById(maxLengthNotes)" + document.getElementById(maxLengthNotes));
var maxLength = document.getElementById(maxLengthNotes).value;
alert("maxLength is:" + maxLength);
if (notesVal != null && notesVal.length > maxLength) {
message = message + replaceMaxLengthMessageTokens(document.getElementById(maxLengthExceedMessage).value, 'Notes', maxLength);
alert("Message :" + message);
} else {
alert("Null Block");
window.console.log("validateFPNotes::notesId.value = " + notesId.value);
}
if (message.length > 1) {
alert(message);
return false;
}
} else {
alert("Null Block");
}
alert("Before return");
return true;
}
除非您的代码遇到错误(在这种情况下将阻止其余代码运行),否则您将return false;
否则, return false;
if (message.length > 1)
。 如果被击中,将永远不会执行您的alert("Before return")
。
终于找到了原因。 由于Windows.console在F12-ing之前不可用,因此出现了问题。 我添加了它,并且在添加了它之后效果很好。
if (window.console && window.console.log) {
window.console.log("validateFanPermissionsNotes::notesId.value = "
+ notesId.value);
}
这里有一个类似的实例: IE首先是抓取我的JS脚本,然后按F12键,它可以正常运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.