如果满足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();
}
});
});
答案 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:
<input type="text" name="data"> Search by:
<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> </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:
<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: </td>
<td colspan="8" align="center" border="1">
<input type="text" name="sub" size="90">
</td>
</tr>
<tr>
<td colspan="2" align="center" border="1">Enter Content: </td>
<td colspan="8" align="center" border="1">
<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: </td>
<td colspan="8" align="center" border="1">
<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>