将单选按钮值从html页面传递到html。

时间:2017-08-28 14:24:13

标签: javascript jquery html

我正在开发一个新的安全评估网页,我正在使用HTML和Java Script。由于某种原因,代码无法正常工作,无法获得所需的结果。代码的工作方式是让用户回答“是”或“否”问题,然后将值传递到整个5个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>

		<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>
  
  

1 个答案:

答案 0 :(得分:0)

存储在localstorage中,并从所有其他页面获取。 例如:localstorage.setItem("RadioVal",'true');

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