我正在编写 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" />
最佳答案
尝试:
if ((txt == "Completed" || txt=="Cancelled") && (dt===null || ct===null)) {
alert("Please Enter the Completed Date and Time");
return false;
}
您必须使用 ||
才能正常工作。
关于javascript - javascript 中多个条件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15637787/