【发布时间】:2011-09-07 21:05:41
【问题描述】:
大家好,我有一个包含 4 个字段的表单 我可以让它检查任何字段是否为空并毫无问题地更改背景颜色,但我遇到的问题是如果所有字段都不为空,则代码不会继续
$(document).ready(function(){
$("#submitpw").click(function(){
var un = $("#FirstName").val();
var pw = $("#LastName").val();
var sid = $("#StudentID").val();
var ss = $("#LastFour").val();
var unl = un.substring(0,un.length - un.length + 1);
var pwl = pw.substring(0,pw.length - pw.length +4)
var emptyTextBoxes = $('.information').filter(function() { return this.value == ""; });
emptyTextBoxes.each(function() {
if ($('.information:empty'))
{
$(this).css("background-color", "red");
alert("Please Enter Information in the Red Fields");
}
else
{
("This is the part that never triggers!!!")
alert("it worked");
$("#campusun").html(unl+pwl+sid+ss);
$("#campuspw").html(sid+ss);
$("#emailun").html(unl+pwl+sid+"@live.tcicollege.edu");
$("#emailpw").html(sid+ss);
}
});
});
});
【问题讨论】:
标签: jquery forms verification if-statement