0
我有這個函數來驗證輸入字段。當出現錯誤時,它應該將東西寫入div元素(它會這樣做!),然後通過jQuerys $('#elementID').show('speed');
來揭示它。函數告訴用戶有關錯誤不會泄露錯誤div
我最近從檢查錯誤到檢查錯誤級別有多高,從而解決了一個更復雜的錯誤報告系統的問題。
功能如下:
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。但是,在我調用函數之後,所有東西都會變成全部。
我花了很多時間讓這個工作沒有成功。
問候,
Akke
有;)它只是不相關的這種情況下,所以我沒有表現出來。它緊挨着輸入框。 –