作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前在使我的 IF 语句工作时遇到问题我希望选择屏蔽“ely”并选择文本框 3 或 4 的用户然后自动勾选文本框 2。
这是我的 JavaScript 代码:
if(showShield.value == ("ely") && document.getElementById("cb3").checked = true; || document.getElementById("cb4").checked = true;)
{
document.getElementById("cb2").checked=true;
}
这可能是错误的,因为它不起作用,所以我如何才能检查用户选择的是文本框 3 还是 4。
这是我的 HTML 代码:
<html>
<head>
<script type="text/javascript" src="myJavascript.js"></script>
</head>
<body>
<select id="likeShield" onchange="showTicks()">
<option value="select1">Select</option>
<option value="yesShield">Yes</option>
<option value="noShield">No</option>
</select>
<select id="showShield" onchange="showTicks()">
<option value="select1">Select</option>
<option value="arc">Arcane</option>
<option value="ely">Elysian</option>
<option value="spec">Spectral</option>
<option value="anylist">Choose any</option>
</select>
<table border = "1">
<tr>
<th> tickbox </th>
<th> shield parts </th>
<th> description </th>
<th> cost </th>
</tr>
<tr>
<td><input type="checkbox" id="cb1"></td>
<td> arc sigil </td>
<td> Large magic part </td>
<td> 5m </td>
</tr>
<tr>
<td><input type="checkbox" id="cb2"></td>
<td> arc shield </td>
<td> A extremely powerful magic shield </td>
<td> 60m </td>
</tr>
<tr>
<td><input type="checkbox" id="cb3"></td>
<td> arc special item </td>
<td> special element </td>
<td> 10m </td>
</tr>
<tr>
<td><input type="checkbox" id="cb4"></td>
<td> elysian sigil </td>
<td> A sigil found by dragons </td>
<td> 50m </td>
</tr>
<tr>
<td><input type="checkbox" id="cb5"></td>
<td> elysian shield </td>
<td> A extremely powerful ranging shield </td>
<td> 40m </td>
</tr>
<tr>
<td><input type="checkbox" id="cb6"></td>
<td> elysian special item </td>
<td> A special attack attached to shield </td>
<td> 25m </td>
</tr>
<tr>
<td><input type="checkbox" id="cb7"></td>
<td> spectral sigil </td>
<td> easily obtainable from goblins </td>
<td> 4m </td>
</tr>
<tr>
<td><input type="checkbox" id="cb8"></td>
<td> spectral shield </td>
<td> Impressive stats </td>
<td> 15m </td>
</tr>
<tr>
<td><input type="checkbox" id="cb9"></td>
<td> spectral special item </td>
<td> Does double damage </td>
<td> 30m </td>
</tr>
</table>
</body>
</html>
最佳答案
if(showShield.value == "ely" && (document.getElementById("cb3").checked || document.getElementById("cb4").checked))//comparison
{
document.getElementById("cb2").checked=true; //asignment
}
&&
在 ||
之前完成所以你需要括号==
,不是=
进行比较(最好是===
,不会自动转换类型,做严格比较)<;
是一个语句终止符,不应在中间使用。关于javascript - 复选框在 IF 语句中被选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13432932/
我是一名优秀的程序员,十分优秀!