Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于特定选定输入的Javascript警报(下拉列表)_Javascript_Jquery - Fatal编程技术网

基于特定选定输入的Javascript警报(下拉列表)

基于特定选定输入的Javascript警报(下拉列表),javascript,jquery,Javascript,Jquery,我的Javascript知识非常有限,因此需要一些帮助,请: 我有以下功能: $('#addDialog').dialog({ autoOpen: false, width: 500, buttons: { "Add": function() { //alert("sent:" + addStartDate.format("dd-MM-yyyy hh:mm:ss tt") + "==" +

我的Javascript知识非常有限,因此需要一些帮助,请:

我有以下功能:

$('#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");
                }

            }

        }
    });

更改以下行

if ($("input[id$=addEventPostCode]").val().length < 5) {

如果任何字符串匹配,结果将为false,If将不会触发警报。

如果我选择假日或疾病,它仍然要求提供邮政编码。这是一行代码:
if($($input[id$=addEventPostCode]).val().length<5&!($(“#addeventsalesson option:selected”).text()=“Holiday”| |$(“#addeventsalesson option:selected”){alert(“Post code不能为空,必须至少包含5个字符”)
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
)