JQuery-如何获取if条件的输出以用作next if条件的输入

时间:2017-09-08 22:14:09

标签: javascript jquery html5

我是Jquery的新手。我试图使用first if条件(".viewvesseltable")的输出来获取vhzchart的值,然后使用其值来运行下一个if条件。但结果总是返回默认条件"声音工程实践(SEP)"。我还要为其余的表添加条件。请帮助解决我的问题。非常感谢所有&堆栈溢出。



$(document).ready(function() {

  $(".vesselcalc").click(function() {

    $(function() {
      if ($("input[type=radio][name=vstate]:checked").val() === 'vgas' && $("input[type=radio][name=vgroup]:checked").val() === 'vgroup1') {
        ($(".viewvesseltable").text("Table 1"));
      } else {
        if ($("input[type=radio][name=vstate]:checked").val() === 'vgas' && $("input[type=radio][name=vgroup]:checked").val() === 'vgroup2') {
          ($(".viewvesseltable").text("Table 2"));
        } else {
          if ($("input[type=radio][name=vstate]:checked").val() === 'vliquid' && $("input[type=radio][name=vgroup]:checked").val() === 'vgroup1') {
            ($(".viewvesseltable").text("Table 3"));
          } else {
            if ($("input[type=radio][name=vstate]:checked").val() === 'vliquid' && $("input[type=radio][name=vgroup]:checked").val() === 'vgroup2') {
              ($(".viewvesseltable").text("Table 4"));
            } else {
              alert("Select Fluid State and Fluid Group");
            }
          }
        }
      }
    });
    var vhzchart = $(".viewvesseltable").val();
    var vpres = $(".vpressure").val();
    var vvol = $(".vvolume").val();
    var vpsv = $(".vpressure").val() * $(".vvolume").val();

    $(function() {
      if ((vhzchart === "Table 1") && (vpres < 0.5)) {
        ($(".viewvesselcategory").text("PED not applicable"));
      } else {
        if ((vhzchart === "Table 1") && ((vpsv > 1000) || (vpres > 1000))) {
          ($(".viewvesselcategory").text("Cat IV"));
        } else {
          if ((vhzchart === "Table 1") && ((vpsv > 200) || (vpres > 200))) {
            ($(".viewvesselcategory").text("Cat III"));
          } else {
            if ((vhzchart === "Table 1") && ((vpsv > 50) || (vpres > 200))) {
              ($(".viewvesselcategory").text("Cat II"));
            } else {
              if ((vhzchart === "Table 1") && (((vvol > 1) && (vpsv > 25)) || (vpres > 200))) {
                ($(".viewvesselcategory").text("Cat I"));
              } {
                ($(".viewvesselcategory").text("Sound Engineering Practice (SEP)"));
              }
            }
          }
        }
      }
    });

  });

});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<article>
  <h2>Vessel</h2> Vessel Name :
  <input type="text">
  <br> Fluid State : Gas
  <input type="radio" name="vstate" value="vgas"> Liquid
  <input type="radio" name="vstate" value="vliquid">
  <br> Fluid Group : Group 1
  <input type="radio" name="vgroup" value="vgroup1"> Group 2
  <input type="radio" name="vgroup" value="vgroup2">
  <br> Design Pressure (Bar) :
  <input type="number" placeholder="Enter Pressure" name="vpressure" class="vpressure">
  <br> Volume (Liters) :
  <input type="number" placeholder="Enter Volume" name="vvolume" class="SmallInput vvolume">
  <p> PED Table : <span class="viewvesseltable"></span></p>
  <p> PED Category: <span class="viewvesselcategory"></span></p>
  <button type="button" class="btn btn-finish pull-left vesselassy">Add to My Assembly</button>
  <button type="button" class="btn btn-primary pull-right vesselcalc">Calculate PED Category</button>
</article>
&#13;
&#13;
&#13;

0 个答案:

没有答案