函数适用于Mozilla但不适用于Eclipse

时间:2015-11-28 14:04:11

标签: javascript html forms cordova

我有一个表单和功能,当使用Mozilla Firefox打开但无法在eclipse上运行时效果很好。它是一个计算BMI的PhoneGap应用程序。该错误表明函数calculate未定义。

这是我第一次在这里发帖,我只是在花了几个小时试图自己解决这个问题之后才这样做。这是我使用的代码:

function calculate(height, weight, gender, age, dweight, efreq) {
  var realbmi = (weight / (height * height));

  //if else variables
  var classification, bmr, advice, daysleft;

  if (realbmi < 18.5) {
    classification = "Underweight";
  } else if ((18.5 <= realbmi) && (realbmi <= 24.99)) {
    classification = "Normal Weight";
  } else if ((25 <= realbmi) && (realbmi <= 29.99)) {
    classification = "Overweight";
  } else if ((30 <= realbmi) && (realbmi <= 34.99)) {
    classification = "Obese (class 1)";
  } else if ((35 <= realbmi) && (realbmi <= 39.99)) {
    classification = "Obese (class 2)";
  } else {
    classfication = "Morbidly Obese";
  }

  if (gender == "male") {
    bmr = (66 + (13.7 * weight) + (5 * height) - (6.8 * age));
  } else {
    bmr = (655 + (9.6 * weight) + (1.8 * height) - (4.7 * age));
  }

  var maintenance = efreq * bmr;

  if (dweight < weight) {
    advice = "You need to lose" + " " + (weight - dweight) + "kg";
  } else if (weight < dweight) {
    advice = "You need to gain" + " " + (dweight - weight) + "kg";
  } else {
    advice = "Try to maintain weight";
  }

  if (dweight < weight) {
    daysleft = "Days to target weight (at 500 cal. less per day):" + ((weight - dweight) / 0.064);
  } else if (dweight > weight) {
    daysleft = "Days to target weight (at 500 cal. more per day):" + ((dweight - weight) / 0.064);
  } else {
    daysleft = "";
  }

  localStorage.setItem("realbmi", realbmi);
  localStorage.setItem("classification", classification);
  localStorage.setItem("bmr", bmr);
  localStorage.setItem("maintenance", maintenance);
  localStorage.setItem("advice", advice);
  localStorage.setItem("daysleft", daysleft);
  localStorage.setItem("weight", parseFloat(document.bmiform.weight.value));
  localStorage.setItem("height", parseFloat(document.bmiform.height.value));
  localStorage.setItem("age", parseFloat(document.bmiform.age.value));
  localStorage.setItem("dweight", parseFloat(document.bmiform.dweight.value));

  document.bmiform.submit();

}
<div data-role="main" class="ui-content">
  <p>Enter your height and weight. The system will calculate your BMI.</p>
  <div class="üi-field-contain">
    <form name="bmiform" id="bmiform" action="bmiresult.html">
      <label for="height">Height</label>
      <input type="text" name="height" id="height" placeholder="enter height in meters">

      <label for="weight">Weight</label>
      <input type="text" name="weight" id="weight" placeholder="enter weight in KG">

      <fieldset data-role="controlgroup" data-type="horizontal">
        <legend>Gender</legend>
        <label for="male">Male</label>
        <input type="radio" name="gender" id="male" value="male" checked>
        <label for="female">Female</label>
        <input type="radio" name="gender" id="female" value="female">
      </fieldset>

      <label for="dweight">Dream Weight</label>
      <input type="text" name="dweight" id="dweight" placeholder="enter dream weight in KG">

      <label for="age">Age</label>
      <input type="text" name="age" id="age" placeholder="enter age">

      <label for="efreq">Exercise Frequency</label>
      <select name="efreq" id="efreq">
        <option value="1.2">Hardly Exercise</option>
        <option value="1.375">Exercise 1 to 3 times per week</option>
        <option value="1.55">Exercise 3 to 5 times per week</option>
        <option value="1.725">Exercise 6 to 7 times per week</option>
        <option value="1.9">Exercise intensively more than 7 times per week</option>
      </select>

      <input type="button" value="Calculate" onclick="calculate(parseFloat(document.bmiform.height.value),parseFloat(document.bmiform.weight.value),
                document.bmiform.gender.value, parseFloat(document.bmiform.age.value), parseFloat(document.bmiform.dweight.value),
                document.bmiform.efreq.value);">

    </form>

0 个答案:

没有答案