什么是可能的解决方案,让JavaScript读取我所有的条件,并显示所有发现的是真的?JavaScript不读取我所有的条件
这里是我的代码:
if (document.getElementById('chk_q1').checked == true) {
if (document.getElementById('chk_c1').checked == false) {
alert('You forgot to check the Competency.')
location.href('index.html');
};
alert('Correct.');
}
if (document.getElementById('chk_q2').checked == true) {
if (document.getElementById('chk_c1').checked == false) {
alert('You forgot to check the Competency.')
location.href('index.html');
};
alert('Correct.');
}
if (document.getElementById('chk_q3').checked == true) {
if (document.getElementById('chk_c1').checked == false) {
alert('You forgot to check the Competency.')
location.href('index.html');
};
alert('Correct.');
}
<form>
<button type="button" class="btn btn-default btn-sm" onclick="javascript:demoPDF()" id="final">Finalized Customized Interview Form</button>
<button type="button" class="btn btn-success btn-sm" onClick="actions.save()">Save</button>
<button type="reset" class="btn btn-warning btn-sm" id="uncheckall">Reset Form</button>
<br>
<br>
<br>
<!-- START OF INTERVIEW INFO -->
<table style="width:100%" id="tbl_info">
<tr>
<th colspan="4">Interview Information</th>
</tr>
<tr>
<td>Hiring Manager Name:</td>
</td>
<td>
<input type="text" name="name" id="HMname" placeholder="Type manager's name here..." style="width:205px">
</td>
</td>
<td>Recruiter Name:</td>
</td>
<td>
<input type="text" name="HMN" id="Rname" placeholder="Type position title here..." style="width:205px">
</td>
</tr>
<tr>
<td>Position Title:</td>
</td>
<td>
<input type="text" name="HMN" id="Ptitle" placeholder="Type recruiter's name here..." style="width:205px">
</td>
</td>
<td>Position Code:</td>
</td>
<td>
<input type="text" name="HMN" id="Pcode" placeholder="Type position code here..." style="width:205px">
</td>
</tr>
<tr>
<td>Candidate Name:</td>
</td>
<td> </td>
</td>
<td>Interview Date:</td>
</td>
<td> </td>
</tr>
</table>
<!-- </form> -->
<!-- END OF INTERVIEW INFO -->
<!-- STRAT OF COMPETENCY -->
<!-- <form action="CC.php" name="select_form"> -->
<!-- <button type="button" class="btn btn-default btn-sm" >Finalized Customized Interview Form</button>
\t \t \t \t <button type="button" class="btn btn-success btn-sm" id="uncheckall" name="uncheckall" alt="save as">Save</button>
\t \t \t \t <button type="button" class="btn btn-warning btn-sm" value="reset" id="uncheckall" name="uncheckall" onclick=>Reset Form</button>
\t \t \t \t <br>
\t \t \t \t <br>
\t \t \t \t <br> -->
<table style="width:100%;margin-top:10px" id="tbl_selection">
<tr>
<th><b>Competency and Select to use for<br> Interview Series</b>
</th>
<th><b>Questions</b>
</th>
<th><b>Use for Interview Series?</b>
</th>
</tr>
<!-- INNOVATION -->
<tr style="background-color:#FEE2B8">
<td rowspan="4"><b>Balance Focus</b>
<br>
<!-- <form> -->
<input type="checkbox" id="chk_c1" onselect="javascript:select()" class="select">Select
<br>
<input type="checkbox" id="not_use" checked>Do not use
<!-- <br>
\t \t \t \t \t \t <input type="radio" name="not_select" value="not selected"> Do not Select -->
<!-- </form> -->
</td>
<td id="q1" value="lorem">Give me an example of a time where you had to make key decisions in the absence of complete information. How did you recognize when a solution is good enough?</td>
<td>
<!-- <form> -->
<input type="checkbox" id="chk_q1">Select
<br>
<input type="checkbox" id="not_use1" checked>Do not use
<!-- <br>
\t \t \t \t \t \t <input type="radio" name="not_select" value="not selected"> Do not Select -->
<!-- </form> -->
</td>
</tr>
<tr>
<td>Describe a situation where you were involved in creating alternative business scenarios, prioritized them based on your knowledge of the business, and put a plan in place to enable the strategy.</td>
<td>
<!-- <form> -->
<input type="checkbox" id="chk_q2">Select
<br>
<input type="checkbox" id="not_use" checked>Do not use
<!-- <br>
\t \t \t \t \t \t \t <input type="radio" name="not_select" value="not selected"> Do not Select -->
<!-- </form> -->
</td>
</tr>
<tr style="background-color:#FEE2B8">
<td>Tell me about a situation in which you were responsible for a project where you had to satisfy multiple stakeholders with different priorities. How did you balance conflicting demands and arrive at a successful outcome?</td>
<td>
<!-- <form> -->
<input type="checkbox" id="chk_q3">Select
<br>
<input type="checkbox" id="not_use" checked>Do not use
<!-- <br>
\t \t \t \t \t \t \t <input type="radio" name="not_select" value="not selected"> Do not Select -->
<!-- </form> -->
</td>
</tr>
<tr>
<td>Tell me about a time when your group was assigned multiple priorities by multiple leaders all stressing the importance of their own projects? How did you prioritize the projects? How did you inform the leaders of their project time frames?</td>
<td>
<!-- <form> -->
<input type="checkbox" id="chk_q4">Select
<br>
<input type="checkbox" id="not_use" checked>Do not use
<!-- <br>
<input type="radio" name="not_select" value="not selected"> Do not Select -->
<!-- </form> -->
</td>
</tr>
</table>
这里的问题是,它只是显示的所有内容,如果我只检查的第一个复选框。
问题的任何解决方案?
你能提供你的HTML吗?这将有助于了解你正在尝试做什么。 – Romulo
如果脚本在html载入前运行,那么'getElementById'将返回null,它没有'checked'属性,导致错误被抛出,并且脚本执行停止。 – HJ05
@Buzinas我将这些阅读为不同的ID,因此可能会有不同的值。可怕的命名,但不同。 –