2017-08-28 141 views
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">&laquo; Previous</a> 
 
<input type="hidden" name="total" id="total" /> 
 
    <input id="submitted" type="Submit" value="Submit"><br><br> 
 
    <p id="demo"></p> 
 

 
</body> 
 
</html> 
 
    
 

+0

所有的单选按钮都有相同的名称,所以它们是同一组的一部分。 – Barmar

+0

*“将值传递给整个5个html页面”* - 你目前如何实现这个目标? – Santi

+0

如果您在未提交表单的情况下更改页面,则必须将其存储到cookie或其他本地变量中。您可能需要考虑分阶段隐藏和/或显示字段集,并从一个HTML页面提交。谷歌多步表单有很多jQuery的例子 – happymacarts

回答

0

存储在localStorage的和其他的页面得到它。 例如:localstorage.setItem("RadioVal",'true');

从localstorage获取其他脚本并在适当的html字段中分配。 例如:var radio1 = localstorage.getItem("RadioVal");