我正在编写javascript函数来检查aspx页面的下拉值是否具有“已完成”或“已取消”的值。如果是,则检查日期和时间是否为空。
但功能永远不会发生。代码如下。
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" />
答案 0 :(得分:1)
此处的问题是您没有为OR
使用正确的运算符。
if ((txt == "Completed" || txt=="Cancelled") && (dt===null || ct===null)) {
...
}
在条件表达式中为||
运算符使用双管道字符OR
。
答案 1 :(得分:1)
尝试:
if ((txt == "Completed" || txt=="Cancelled") && (dt===null || ct===null)) {
alert("Please Enter the Completed Date and Time");
return false;
}
你必须使用||
才能正常工作。