调用以下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;
}
答案 0 :(得分:0)
除非您的代码遇到错误,否则会阻止其余代码运行,您需要return false;
if (message.length > 1)
。如果这被击中,您的alert("Before return")
将永远不会被执行。
答案 1 :(得分:0)
if (window.console && window.console.log) {
window.console.log("validateFanPermissionsNotes::notesId.value = "
+ notesId.value);
}
此处有一个simila实例:I.E. craches my JS script at first, then i press F12 and it works beaultifully