简体   繁体   English

基于输入值的表格计算器

[英]Form calculator based on input values

I am working on a Cardio Test calculator which calculates heart attack risk. 我正在使用Cardio Test计算器来计算心脏病发作的风险。 I want to get score based value for each input. 我想为每个输入获取基于分数的值。 The results logic is already working, I just need to get result score value. 结果逻辑已经在起作用,我只需要获取结果得分值即可。 See the code below. 请参见下面的代码。

<script>
$(document).ready(function() {
  $("#female").change(function() {
    if ($(this).is(":checked")) {
      $("#femaleage").show();
      $("#maleage").hide();
    }
  });

  $("#male").change(function() {
    if ($(this).is(":checked")) {
      $("#maleage").show();
      $("#femaleage").hide();
    }
  });

  $( "#cardio__test" ).submit(function( event ) {
    event.preventDefault();
    if ($("#score").val() <= 3) {
      $(".risk__score.low__risk").show();
    } 

    if ($("#score").val() >= 4 && $("#score").val() <= 6) {
      $(".risk__score.moderate__risk").show();
    }

    if ($("#score").val() >= 7) {
      $(".risk__score.high__risk").show();
    }

    if ($("#maleage").val() >= 70) {
      $("#score").val() + 8;
    }

    $(this).hide();
  });



});

</script>

Here's a link ! 这是一个链接

I tested out your codepen and I found out the value of your score is a string type instead of int as I tested using parseInt() and typeof ... and the result string value is blank (maybe i changed some code in the codepen during testing) How do you check the value of the score and do you get it as a number ? 我测试了您的Codepen,发现您的分数值是字符串类型,而不是我使用parseInt()typeof ...进行测试的int ...结果字符串值为空白(也许我在测试期间更改了Codepen中的某些代码测试)您如何检查分数的值并获得数字
Anyway, to print out the result value you can do it in many ways such as 无论如何,要打印出结果值,您可以通过多种方式进行处理,例如

  • adding a new div in your results div and print the results inside the div 结果 div中添加新的div在div中打印结果

    $(".(new div class name) h3").text($("#score").val());

  • or simply alert the results 或只是警告结果

    alert($("#score").val());

你可以简单地使用

var scoreValue = $("#score").val();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM