$(document).ready(function () {
$("#submit").click(function () {
$(".error").hide();
var hasError = false;
var code = $("#code").val();
if (code == '') {
$("#code").after('<span class="error">Enter code .</span>');
hasError = true;
}
else if (code <= 1) {
$("#code").after('<span class="error">Enter at least 2 charecter.</span>');
hasError = true;
}
if (hasError == true) { return false; }
});
});
对于null检查工作正常,但else if条件不起作用并进入服务器站点验证
答案 0 :(得分:1)
嗨Dalim使用长度属性,如下所示,在其他情况下。
var code = $("#code").val();
if (code == '') {
$("#code").after('<span class="error">Enter code .</span>');
hasError = true;
}
else if (code.length <= 1) {
$("#code").after('<span class="error">Enter at least 2 charecter.</span>');
hasError = true;
}
if (hasError == true) { return false; }