$(function()
{
$("#btnMessage").click(function()
{
var name = $("#txtName").val();
var phone = $("#txtPhone").val();
var pizzaBase = $("#cboBase").val();
var pizzaSize = $("input[name=radSize]:checked").val();
message = "";
if (name == "")
{
message += "--Enter a name\n";
}
if (phone == "")
{
message += "--Enter a valid phone number - 999-999-9999\n";
}
if (pizzaBase == "0")
{
message += "--Select a base pizza\n";
}
if (pizzaSize == undefined)
{
message += "--Select a pizza Size";
}
/*else
{
message = name;
alert(total);
}*/
});
});
所以,如果我在验证过程中遗漏了一些内容。即如果我错过了名字和一切。如何使警报显示该消息变量? 在什么情况下if语句应该是什么?
答案 0 :(得分:1)
$(function()
{
$("#btnMessage").click(function()
{
var name = $("#txtName").val();
var phone = $("#txtPhone").val();
var pizzaBase = $("#cboBase").val();
var pizzaSize = $("input[name=radSize]:checked").val();
message = "";
if (name == "")
{
message += "--Enter a name\n";
}
if (phone == "")
{
message += "--Enter a valid phone number - 999-999-9999\n";
}
if (pizzaBase == "0")
{
message += "--Select a base pizza\n";
}
if (pizzaSize == undefined)
{
message += "--Select a pizza Size";
}
if(message)
{
alert(total);
} else {
//Continue your processing
}
});
});