3

这是我的代码,我不明白出了什么问题。

    <script type="text/jquery">

function gettotalAdult()
{
    //Assume form with id="fsd-bucket-calc"
    var theForm = document.forms["fsd-bucket-calc"];
    //Get a reference to the # of Adults & Children
    var quantity = theForm.elements["totalAdult"];
    var caloriesAdult = theForm.elements["caloriesAdult"];
    var adultcalTotal=0;
    //If the totalAdult is not blank
    if(totalAdult.value!="")
    {
        adultcalTotal = parseInt(totalAdult.value)*parseInt(caloriesAdult.value);
    }
return adultcalTotal;
}

function gettotalChild()
{
    //Assume form with id="fsd-bucket-calc"
    var theForm = document.forms["fsd-bucket-calc"];
    //Get a reference to the # of Children
    var totalChild = theForm.elements["totalChild"];
    var caloriesChild = theForm.elements["caloriesChild"];
    var childcalTotal=0;
    //If the totalChild is not blank
    if(totalChild.value!="")
    {
        childcalTotal = parseInt(totalChild.value)*parseInt(caloriesChild.value);
    }
return childcalTotal;
}

function gettotalCalories()
{
    //Here we get the total calories by calling our function
    //Each function returns a number so by calling them we add the values they return together
    var totalCalories = gettotalAdult() + gettotalChild();
    //display the result
    document.getElementById('total-req-cal').innerHTML = "The total required calories are "+totalCalories;
}

</script>

这是我的 HTML:

<input type="text" name="totalAdult" id="totalAdult" onkeyup="gettotalCalories()" />

这是我的错误:

gettotalCalories 未定义

如果有帮助,该脚本位于 WordPress 页面的头部。有谁看到我做错了什么?

4

1 回答 1

6

你有<script type="text/jquery">你可能需要<script type="text/javascript">代替。

于 2011-10-23T00:18:32.213 回答