jquery或逻辑失败只运行一半或语句

时间:2015-09-16 17:28:23

标签: jquery

如果满足2个参数中的任何一个,我试图在Jquery运行中执行操作

如果选择umodt =“终止”或“删除”

但是我的逻辑只在=“删除”时触发 - 请帮助

new A().init()

HTML引用:

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

    });
  });

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

你可以试试这个(

使用||而不是逗号):

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

    });
  });
</script>