如何将JavaScript结果显示为段落

How to display a JavaScript result as a paragraph?

本文关键字:显示 段落 结果 JavaScript      更新时间:2023-09-26

我一直在使用一个javascript来计算一个人的BMI。但对于BMI结果,我想显示特定结果组的具体评论。我该怎么做?这是脚本:

<script>
    <!--
        function calculateBmi() 
            {
                var weight = document.bmiForm.weight.value
                var height = document.bmiForm.height.value
                    if(weight > 0 && height > 0)
                        {   
                            var stadnardwight1 = 19*height/100*height/100
                                document.bmiForm.weight1.value = stadnardwight1
                            var stadnardwight2 = 25*height/100*height/100
                                document.bmiForm.weight2.value = stadnardwight2
                            var finalBmi = weight/(height/100*height/100)
                                document.bmiForm.bmi.value = finalBmi
                                    if(finalBmi < 19)
                                        {
                                            document.bmiForm.meaning.value = "That you are too thin."
                                        }
                                    if(finalBmi > 19 && finalBmi < 25)
                                        {
                                            document.bmiForm.meaning.value = "That you are healthy."
                                        }
                                    if(finalBmi > 25)
                                        {
                                            document.bmiForm.meaning.value = "That you have overweight."
                                        }
                        }
                else
                    {
                        alert("Please Fill in everything correctly")
                    }
            }
    //-->
    </script>
    <form name="bmiForm">
    Your Weight(kg): <input type="text" name="weight" size="10"><br />
    Your Height(cm): <input type="text" name="height" size="10"><br />
    <input type="button" value="Calculate BMI" onClick="calculateBmi()"><br />
    Your BMI: <input type="text" name="bmi" size="10"><br />
    This Means: <input type="text" name="meaning" size="25"><br />
    Your weight should be between: <input type="text" name="weight1" size="10"> to <input type="text" name="weight2" size="10"> kg<br />
    <input type="reset" value="Reset" />
    </form>

这里,通过从输入的文本来显示含义值。但是如何将其显示为段落,而不是文本输入呢?

提前感谢您的帮助。

注意:含义将根据3种不同类别的结果而变化。如果你能给出一个解决方案的代码行示例,那将是非常有帮助的

不要使用'input'标记来表示含义,而是使用'span'标记,并将该span的innerHtml设置为所需内容。