2015-09-16 42 views
0

我試圖讓jQuery中的動作運行,如果任2個參數滿足jQuery的或邏輯錯誤只能在運行的一半或聲明

如果選擇umodt =「終止」或「刪除」

然而,我的邏輯是隻有射擊時= 「刪除」 - 請幫助

$(document).ready(function() { 
    $("#umodt select").change(function (e) { 
     if ($(this).val() != "Terminate", $(this).val() != "Delete") { 
     $("#disreas").hide(); 
     } 
     else { 
     $("#disreas").show(); 
      } 

    }); 
    }); 

HTML引用:

<div id="acttype"><table bgcolor="#CCCCFF" bordercolor="#000000" border="1" width="700"><tr><td colspan="6" align="center" border="1">Search Data:&nbsp;&nbsp;<input type="text" name="data">&nbsp;&nbsp;&nbsp;&nbsp;Search by:&nbsp;&nbsp;<select id="acttype" name="acttype"><option value=" "> </option><option value="Last Name">Last Name</option><option value="First Name">First Name</option><option value="Email">E-mail</option><option value="SSN">SSN</option><option value="Reset">Reset Conditions</option></select>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table></div><div id="umodt"><table bgcolor="#CCCCFF" bordercolor="#000000" width="700" border="1"><tr><td colspan="6" align="center" border="1"> Or Select Action:&nbsp;&nbsp;<select id="umodt" name="umodt"><option value=" "> </option><option value="View">View Employee</option><option value="Add">Add Employee</option><option value="Edit">Edit Employee</option><option value="Delete">Delete Employee</option><option value="Terminate">Terminate Employee</option><option value="Sendemail">Send Message</option></select></td></tr></table></div><div id="emails"><table bgcolor="#CCCCFF" bordercolor="#000000" width="700" border="1"><tr><td colspan="2" align="center" border="1"> Enter Subject:&nbsp;</td><td colspan="8" align="center" border="1">&nbsp;<input type="text" name="sub" size="90"></td></tr><tr><td colspan="2" align="center" border="1">Enter Content:&nbsp;</td><td colspan="8" align="center" border="1">&nbsp;<textarea name="content" rows="7" cols="68"></textarea></td></tr></table></div><div id="disreas"><table bgcolor="#CCCCFF" bordercolor="#000000" width="700" border="1"><tr><td colspan="2" align="center" border="1"> Enter Reason:&nbsp;</td><td colspan="8" align="center" border="1">&nbsp;<input type="text" name="reason" size="90"></td></tr></table></div><table bgcolor="#CCCCFF" bordercolor="#000000" width="700"><tr><td colspan="10" align="center" ><input type="submit" name="submit" value="Submit"></td></tr></table> 
+0

使用||而不是逗號 – Mark

回答

3

您需要使用的logical AND &&代替,

$(document).ready(function() { 
 
    $("select#umodt").change(function(e) { 
 
    if (this.value != "Terminate" && this.value != "Delete") { 
 
     $("#disreas").hide(); 
 
    } else { 
 
     $("#disreas").show(); 
 
    } 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div id="acttype"> 
 
    <table bgcolor="#CCCCFF" bordercolor="#000000" border="1" width="700"> 
 
    <tr> 
 
     <td colspan="6" align="center" border="1">Search Data:&nbsp;&nbsp; 
 
     <input type="text" name="data">&nbsp;&nbsp;&nbsp;&nbsp;Search by:&nbsp;&nbsp; 
 
     <select id="acttype" name="acttype"> 
 
      <option value=" "></option> 
 
      <option value="Last Name">Last Name</option> 
 
      <option value="First Name">First Name</option> 
 
      <option value="Email">E-mail</option> 
 
      <option value="SSN">SSN</option> 
 
      <option value="Reset">Reset Conditions</option> 
 
     </select>&nbsp;&nbsp;&nbsp;&nbsp;</td> 
 
    </tr> 
 
    </table> 
 
</div> 
 
<div id="umodt"> 
 
    <table bgcolor="#CCCCFF" bordercolor="#000000" width="700" border="1"> 
 
    <tr> 
 
     <td colspan="6" align="center" border="1">Or Select Action:&nbsp;&nbsp; 
 
     <select id="umodt" name="umodt"> 
 
      <option value=" "></option> 
 
      <option value="View">View Employee</option> 
 
      <option value="Add">Add Employee</option> 
 
      <option value="Edit">Edit Employee</option> 
 
      <option value="Delete">Delete Employee</option> 
 
      <option value="Terminate">Terminate Employee</option> 
 
      <option value="Sendemail">Send Message</option> 
 
     </select> 
 
     </td> 
 
    </tr> 
 
    </table> 
 
</div> 
 
<div id="emails"> 
 
    <table bgcolor="#CCCCFF" bordercolor="#000000" width="700" border="1"> 
 
    <tr> 
 
     <td colspan="2" align="center" border="1">Enter Subject:&nbsp;</td> 
 
     <td colspan="8" align="center" border="1">&nbsp; 
 
     <input type="text" name="sub" size="90"> 
 
     </td> 
 
    </tr> 
 
    <tr> 
 
     <td colspan="2" align="center" border="1">Enter Content:&nbsp;</td> 
 
     <td colspan="8" align="center" border="1">&nbsp; 
 
     <textarea name="content" rows="7" cols="68"></textarea> 
 
     </td> 
 
    </tr> 
 
    </table> 
 
</div> 
 
<div id="disreas"> 
 
    <table bgcolor="#CCCCFF" bordercolor="#000000" width="700" border="1"> 
 
    <tr> 
 
     <td colspan="2" align="center" border="1">Enter Reason:&nbsp;</td> 
 
     <td colspan="8" align="center" border="1">&nbsp; 
 
     <input type="text" name="reason" size="90"> 
 
     </td> 
 
    </tr> 
 
    </table> 
 
</div> 
 
<table bgcolor="#CCCCFF" bordercolor="#000000" width="700"> 
 
    <tr> 
 
    <td colspan="10" align="center"> 
 
     <input type="submit" name="submit" value="Submit"> 
 
    </td> 
 
    </tr> 
 
</table>

+0

不確定爲什麼,但此語法已將其更改爲不顯示刪除 –

+0

@JamesStafford:請添加您的html代碼 –

+0

已添加HTML - 我道歉它是1行;它由PHP創建並且仍在清理中 –

0

你可以試試這個(

使用||而不是逗號):

<script> 
    $(document).ready(function() { 
    $("#umodt select").change(function (e) { 
     if ($(this).val() != "Terminate" || $(this).val() != "Delete") { 
     $("#disreas").hide(); 
     } 
     else { 
     $("#disreas").show(); 
      } 

    }); 
    }); 
</script>