2013-03-26 52 views
0

我正在编写javascript函数来检查aspx页面的下拉值是否具有值“已完成”或“已取消”。如果它检查日期和时间是否不为空。 但功能永远不会触发。代码如下。
多个条件不在javascript中触发

function EnableValidator() { 
    var drp = document.getElementById('<%=drpcallstatus.ClientID %>'); 
    var txt = drp.options[drp.selectedIndex].text; 
    var dt = document.getElementById('<%=txtcompletedate.ClientID %>'); 
    var ct = document.getElementById('<%=txtcomptime.ClientID %>'); 



    if ((txt == "Completed" | txt=="Cancelled") && (dt===null | ct===null)) { 

      alert("Please Enter the Completed Date and Time"); 

      return false; 

    } 

的功能是从asp.net按钮

<asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClientClick="return EnableValidator()" onclick="btnsubmit_Click" /> 
+6

|无效,请使用||而不是'或'运营商。 – lifetimes 2013-03-26 13:05:51

+1

你可以分享选择的呈现HTML吗? – jackJoe 2013-03-26 13:05:59

+0

@jackJoe呈现的HTML选择格式为 - 罗汉39秒前 – Rohan 2013-03-28 06:03:28

回答

1

称为这里的问题是,你没有使用正确的操作为您OR

if ((txt == "Completed" || txt=="Cancelled") && (dt===null || ct===null)) { 
    ... 
} 

使用双重管字符||用于在条件表达式的OR运算符。

+2

这是* Javascript *而非* PHP *(你链接了PHP文档),虽然'OR'运算符是相同的:) – jackJoe 2013-03-26 13:23:33

+0

@jac - 哎呀!感谢您的反馈! :P – Lix 2013-03-26 13:51:15

+0

谢谢你的回应。我也试过,但它仍然没有着火。我用||即使条件不匹配,也会发出'&&'的警报。我认为条件写入的方式是错误的或是什么。 – Rohan 2013-03-28 05:52:06

1

尝试:

if ((txt == "Completed" || txt=="Cancelled") && (dt===null || ct===null)) { 
      alert("Please Enter the Completed Date and Time"); 
      return false; 
} 

你必须使用||为它工作。

+0

:没有解决方案家伙????? – Rohan 2013-03-30 05:27:18