告诉用户错误的函数不会显示错误 div
我有这个函数来验证输入字段。当出现问题时,它应该将内容写入 div 元素(确实如此!),然后通过 jQuery $('#elementID').show('speed');
显示它。
我最近从检查是否有错误改为检查错误级别有多高,用更复杂的错误报告系统解决问题。
该函数如下所示:
function verifyKassaAle() {
var TOS_K_alevalue = $('#TOS_K_ale').val();
if (!(TOS_K_alevalue == "")) {
if (TOS_K_alevalue <= 100) {
if (TOS_K_alevalue > 0) {
if (TOS_K_alevalue > 2) {
var a = confirm("Kassa ale on enemmän kuin 2%, onko tämä OK?");
if (a == true) {
if(errorlevel > 0) {
errorlevel = errorlevel - 1;
}
else if(errorlevel == 0) {
errorlevel = 0;
}
} else {
if(errorlevel > 0) {
errorlevel = errorlevel - 1;
}
else if(errorlevel == 0) {
errorlevel = 0;
}
showinfo = showinfo + 1;
info = "Kassa ale on yli 2%"
}
} else {
if(errorlevel > 0) {
errorlevel = errorlevel - 1;
}
else if(errorlevel == 0) {
errorlevel = 0;
}
}
} else {
errorlevel = errorlevel + 1;
Errormsg = "Kassa ale on alle 0%";
}
} else {
errorlevel = errorlevel + 1;
Errormsg = "Kassa ale on yli 100%";
}
} else {
errorlevel = errorlevel + 1;
Errormsg = "Kassa ale on tyhjä!";
}
if(errorlevel == 0) {
$('#errormsg').html('');
$('#error').hide('fast');
$('#TOS_K_ale_valid').html('<td><div class="ui-state-default ui-corner-all" title="Valid!" style="margin-bottom:-5px;"><span class="ui-icon ui-icon-check"></span></div></td>');
} else {
$('#errormsg').html(Errormsg);
$('#error').show('fast');
$('#TOS_K_ale_valid').html('<td><div class="ui-state-default ui-corner-all" title="Not valid!" style="margin-bottom:-5px;"><span class="ui-icon ui-icon-alert"></span></div></td>');
}
if(showinfo > 0) {
$('#infotext_kale').html(info);
$('#info').show('fast');
} else {
$('#infotext_kale').html('');
$('#info').hide('fast');
}
$('#TOS_K_ale_valid').show('slow');
}
错误/信息 div 如下所示:
<div id="error" style="margin-top:5px;display:none;">
<div class="ui-state-error ui-corner-all" style="padding:0.7em;font-size:13px;">
<span class="ui-state-error-text">
<span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;margin-bottom:-5px;"></span>
</span>
<strong>VIKA: </strong>
<span id="errormsg"></span>
</div>
</div>
<div id="info" style="margin-top:5px;display:none;">
<div class="ui-state-highlight ui-corner-all" style="padding:0.7em;font-size:13px;">
<span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;margin-bottom:-5px;"></span>
<strong>Huom: </strong>
<span id="infotext"></span>
</div>
</div>
所以,我可以在该函数执行之前从 firebugs 控制台调用 $('#error').show('fast')
被调用并且它很好地显示了 div 。然而,在我调用该函数之后,一切都恢复正常了。
我花了很多时间来让它工作但没有成功。
问候,
阿克
I have this function to validate an input field. When something is wrong it should write stuff into a div element (which it does!) and then reveal it through jQuerys $('#elementID').show('speed');
.
I recently changed from checking if there was an error to checking how high the errorlevel is, solving a problem with a more complex error-reporting system.
The function looks like this:
function verifyKassaAle() {
var TOS_K_alevalue = $('#TOS_K_ale').val();
if (!(TOS_K_alevalue == "")) {
if (TOS_K_alevalue <= 100) {
if (TOS_K_alevalue > 0) {
if (TOS_K_alevalue > 2) {
var a = confirm("Kassa ale on enemmän kuin 2%, onko tämä OK?");
if (a == true) {
if(errorlevel > 0) {
errorlevel = errorlevel - 1;
}
else if(errorlevel == 0) {
errorlevel = 0;
}
} else {
if(errorlevel > 0) {
errorlevel = errorlevel - 1;
}
else if(errorlevel == 0) {
errorlevel = 0;
}
showinfo = showinfo + 1;
info = "Kassa ale on yli 2%"
}
} else {
if(errorlevel > 0) {
errorlevel = errorlevel - 1;
}
else if(errorlevel == 0) {
errorlevel = 0;
}
}
} else {
errorlevel = errorlevel + 1;
Errormsg = "Kassa ale on alle 0%";
}
} else {
errorlevel = errorlevel + 1;
Errormsg = "Kassa ale on yli 100%";
}
} else {
errorlevel = errorlevel + 1;
Errormsg = "Kassa ale on tyhjä!";
}
if(errorlevel == 0) {
$('#errormsg').html('');
$('#error').hide('fast');
$('#TOS_K_ale_valid').html('<td><div class="ui-state-default ui-corner-all" title="Valid!" style="margin-bottom:-5px;"><span class="ui-icon ui-icon-check"></span></div></td>');
} else {
$('#errormsg').html(Errormsg);
$('#error').show('fast');
$('#TOS_K_ale_valid').html('<td><div class="ui-state-default ui-corner-all" title="Not valid!" style="margin-bottom:-5px;"><span class="ui-icon ui-icon-alert"></span></div></td>');
}
if(showinfo > 0) {
$('#infotext_kale').html(info);
$('#info').show('fast');
} else {
$('#infotext_kale').html('');
$('#info').hide('fast');
}
$('#TOS_K_ale_valid').show('slow');
}
And the error/info divs look like this:
<div id="error" style="margin-top:5px;display:none;">
<div class="ui-state-error ui-corner-all" style="padding:0.7em;font-size:13px;">
<span class="ui-state-error-text">
<span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;margin-bottom:-5px;"></span>
</span>
<strong>VIKA: </strong>
<span id="errormsg"></span>
</div>
</div>
<div id="info" style="margin-top:5px;display:none;">
<div class="ui-state-highlight ui-corner-all" style="padding:0.7em;font-size:13px;">
<span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;margin-bottom:-5px;"></span>
<strong>Huom: </strong>
<span id="infotext"></span>
</div>
</div>
SO, I can call $('#error').show('fast')
from firebugs' console BEFORE this function has been called and it shows the div nicely. However, after I have called the function everything gets all ft up.
I have spent many hours to get this working without success.
Regards,
Akke
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有这个 jQuery 选择器
$('#TOS_K_ale_valid')
并且 html 中没有带有id="TOS_K_ale_valid"
的元素。You have this jQuery selector
$('#TOS_K_ale_valid')
and there is no element withid="TOS_K_ale_valid"
in html.