0
我正在使用HTML和Java腳本的新安全評估網頁。出於某種原因,代碼無法正常工作,無法獲得理想的結果。代碼應該工作的方式是讓用戶回答是或否問題,然後將值傳遞到整個5個HTML頁面,直到用戶單擊提交時的最後一頁爲止。然後頁面將顯示回答爲yes的問題數量。將單選按鈕值從html頁面傳遞給html。
任何幫助將不勝感激。
感謝,
<script>
$('.calc').change(function() {
calcscore();
});
$('#submitted').click(function() {
sumInputs();
result();
});
function sumInputs() {
var inputs = $('.calc:checked'),
result = $('#total').val(),
sum = 0;
for (var i = 0; i < inputs.length; i++) {
sum += parseInt(inputs[i].value);
}
$('#total').val(sum);
}
function calcscore() {
var score = 0;
$('.calc:checked').each(function() {
score += parseInt($(this).val(), 10);
});
$('#total').val(score);
}
</script>
-------------------------------------------------
(Last java script code)
<script>
$('.calc').change(function() {
calcscore();
});
$('#submitted').click(function() {
sumInputs();
result();
});
function sumInputs() {
var inputs = $('.calc:checked'),
result = $('#total').val(),
sum = 0;
for (var i = 0; i < inputs.length; i++) {
sum += parseInt(inputs[i].value);
}
$('#total').val(sum);
}
function result() {
var text;
var score = (($('#total').val())/57) * 100;
var score = score.toFixed(1);
if (score < 60) {
alert (text = "Total score " + score + ": You have failed the Assessment");
}
else {
alert (text = "Total score " + score + ": You have passed the Assessment");
}
$('#demo').text(text);
}
function calcscore() {
var score = 0;
$('.calc:checked').each(function() {
score += parseInt($(this).val(), 10);
});
$('#total').val(score);
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!DOCTYPE html>
<html>
\t \t <body>
<table>
<th>PHYSICAL SECURITY </th>
<tr>
<td>7. Do you have policies and procedures that address allowing authorized and
limiting unauthorized physical access to electronic information systems and the
facilities in which they are housed?
<form>
Yes
<input class="calc" type="radio" name="radio4" value="1" /> <br />
No
<input class="calc" type="radio" name="radio4" value="0" /> <br />
N/A
<input class="calc" type="radio" name="radio4" value="0" /> <br />
</form>
</td>
</tr>
<tr>
<td>8. Do your policies and procedures specify the methods used to control physical
access to your secure areas, such as door locks, access control systems,
security officers, or video monitoring?
<form>
Yes
<input class="calc" type="radio" name="radio4" value="1" /> <br />
No
<input class="calc" type="radio" name="radio4" value="0" /> <br />
N/A
<input class="calc" type="radio" name="radio4" value="0" /> <br />
</form>
</td>
</tr>
</table>
</body>
</html>
---------------------------------------
Last html Page
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<table>
<tr>
<th>COMPLIANCE AND AUDIT</th>
</tr>
<
<tr>
<td>54. Do you review and revise your security documents, such as: policies,
standards, procedures, and guidelines, on a regular basis?
<form>
Yes
<input class="calc" type="radio" name="radio4" value="1" /> <br />
No
<input class="calc" type="radio" name="radio4" value="0" /> <br />
N/A
<input class="calc" type="radio" name="radio4" value="0" /> <br />
</form>
</td>
</tr>
<tr>
<td>55. Do you audit your processes and procedures for compliance with established
policies and standards?
<form>
Yes
<input class="calc" type="radio" name="radio4" value="1" /> <br />
No
<input class="calc" type="radio" name="radio4" value="0" /> <br />
N/A
<input class="calc" type="radio" name="radio4" value="0" /> <br />
</form>
</td>
</tr>
<tr>
<td>56. Do you test your disaster plans on a regular basis?
<form>
Yes
<input class="calc" type="radio" name="radio4" value="1" /> <br />
No
<input class="calc" type="radio" name="radio4" value="0" /> <br />
N/A
<input class="calc" type="radio" name="radio4" value="0" /> <br />
</form>
</td>
</tr>
</table>
<a href="secEdu.html" class="previous">« Previous</a>
<input type="hidden" name="total" id="total" />
<input id="submitted" type="Submit" value="Submit"><br><br>
<p id="demo"></p>
</body>
</html>
所有的單選按鈕都有相同的名稱,所以它們是同一組的一部分。 – Barmar
*「將值傳遞給整個5個html頁面」* - 你目前如何實現這個目標? – Santi
如果您在未提交表單的情況下更改頁面,則必須將其存儲到cookie或其他本地變量中。您可能需要考慮分階段隱藏和/或顯示字段集,並從一個HTML頁面提交。谷歌多步表單有很多jQuery的例子 – happymacarts