JavaScript的alert(下拉列表)
问题描述:
我有非常有限的JavaScript知识,需要一些帮助,请:JavaScript的alert(下拉列表)
我有以下功能:
$('#addDialog').dialog({
autoOpen: false,
width: 500,
buttons: {
"Add": function() {
//alert("sent:" + addStartDate.format("dd-MM-yyyy hh:mm:ss tt") + "==" + addStartDate.toLocaleString());
var eventToAdd = {
//title: $("#addEventName").val(),
title: $("#addEventSalesPerson option:selected").text(),
description: $("#addEventDesc").val(),
start: addStartDate.format("dd-MM-yyyy hh:mm:ss tt"),
end: addEndDate.format("dd-MM-yyyy hh:mm:ss tt"),
salesperson: $("#addEventSalesPerson option:selected").text(),
eventPostCode: $("input[id$=addEventPostCode]").val(),
eventname: $("#addEventEventName option:selected").text()
};
if ($("input[id$=addEventPostCode]").val().length < 5) {
alert("Post code cannot be blank and must contain a minimum of 5 characters");
}
else {
//alert("sending " + eventToAdd.title);
PageMethods.addEvent(eventToAdd, addSuccess);
$(this).dialog("close");
}
}
}
});
#addEventEventName
是填充的DDL SQL并有几个选项。目前,如果"input[id$=addEventPostCode]"
少于5个字符,则会发出警报。
我需要的是,如果选择的选项假日或疾病那么它不会显示一个警告。谢谢
更新 我试着按@戴维的建议添加下面的行,但仍然没有喜悦 - 任何接受者?
if ($("input[id$=addEventPostCode]").val().length < 5 && !($("#addEventSalesPerson option:selected").text() == "Holiday" || $("#addEventSalesPerson option:selected").text() == "Sickness")) {
答
更改以下行
if ($("input[id$=addEventPostCode]").val().length < 5) {
到
if ($("input[id$=addEventPostCode]").val().length < 5 && !($("#addEventSalesPerson option:selected").text() == "Holiday" || $("#addEventSalesPerson option:selected").text() == "Sickness")) {
它应该如果只警告不放假或疾病
! //This is Not
(//Parenthesis group expressions together so the not works on the result of the expressions inside
$("#addEventSalesPerson option:selected").text() == "Holiday" //This checks if selected text matches string
|| //This means Or
$("#addEventSalesPerson option:selected").text() == "Sickness" //This checks if selected text matches string
)
如果任何字符串匹配结果将是错误的,我f不会触发警报。
如果我选择假日或疾病,它仍然会要求邮政编码。这里是一行代码:'if($(“input [id $ = addEventPostCode]”).val().length James 2011-03-02 19:18:34