Java脚本中的IF语句,并在消息变量中链接到新的html页面

吉尔

请您能帮我获取Java脚本中的if语句吗?

另外,我在我的消息变量中添加了指向新页面的链接,但是我认为这是不对的,对此,我们将不胜感激。

var messageLow = "Your results show that you currently have a low risk of developing diabetes. However, it is important that you maintain a healthy lifestyle in terms of diet and exercise.";
var messageMed = "Your results show that you currently have a medium risk of developing diabetes. For more information on your risk factors, and what to do about them, please visit our diabetes advice website at http://www.zha.org.zd/";
var messageHigh1 = "Your results show that you currently have a HIGH risk of developing diabetes. Your main risk factors are your age and your BMI. We advise that you contact the Health Authority to discuss your risk factors as soon as you can. Please fill in our contact form and a member of the Health Authority Diabetes Team will be in contact with you.";
                "Please click on this link to fill out a contact form:" <a href=contactForm.html>contact form</a>
var messageHigh2 =  "Your results show that you currently have a HIGH risk of developing diabetes. Your main risk factors are your age and your family history. We advise that you contact the Health Authority to discuss your risk factors as soon as you can. Please fill in our contact form and a member of the Health Authority Diabetes Team will be in contact with you.";
                "Please click on this link to fill out a contact form:" <a href=contactForm.html>contact form</a>
var messageHigh3 =  "Your results show that you currently have a HIGH risk of developing diabetes. Your main risk factors are your age and your sugar levels. We advise that you contact the Health Authority to discuss your risk factors as soon as you can. Please fill in our contact form and a member of the Health Authority Diabetes Team will be in contact with you.";
                "Please click on this link to fill out a contact form:" <a href=contactForm.html>contact form</a>
 var messageHigh4 =  "Your results show that you currently have a HIGH risk of developing diabetes. Your main risk factors are your BMI and family history. We advise that you contact the Health Authority to discuss your risk factors as soon as you can. Please fill in our contact form and a member of the Health Authority Diabetes Team will be in contact with you.";
                "Please click on this link to fill out a contact form:" <a href=contactForm.html>contact form</a>
var messageHigh5 =  "Your results show that you currently have a HIGH risk of developing diabetes. Your main risk factors are your BMI and your sugar levels. We advise that you contact the Health Authority to discuss your risk factors as soon as you can. Please fill in our contact form and a member of the Health Authority Diabetes Team will be in contact with you.";
                "Please click on this link to fill out a contact form:" <a href=contactForm.html>contact form</a>
var messageHigh6 =  "Your results show that you currently have a HIGH risk of developing diabetes. Your main risk factors are your family history and your sugar levels. We advise that you contact the Health Authority to discuss your risk factors as soon as you can. Please fill in our contact form and a member of the Health Authority Diabetes Team will be in contact with you.";
                "Please click on this link to fill out a contact form:" <a         href=contactForm.html>contact form</a>

 function displayMsg()
 {
    var age, bmi, family, sugar;
    age = document.querySelector('input[name = "age"]:checked').value;
    bmi = document.querySelector('input[name = "bmi"]:checked').value;
    family = document.querySelector('input[name = "family"]:checked').value;
    sugar = document.querySelector('input[name = "sugar"]:checked').value;

    var total = age + bmi + family + sugar;

    document.getElementById("container").innerHTML = "<b>Your result: </b><br>";

    if( total >= 0 && total <= 15)
    {
        document.getElementById("container").innerHTML += messageLow;

    }
    else if(total >= 16 && total <= 25)
    {
        document.getElementById("container").innerHTML += messageMed;

    }
    elseif (total > 25)
    {

        if (age=>10 && bmi =>10)
    }{
         document.getElementById("container").innerHTML += messageHigh1;
        }
    {
         if (age=>10 && family =>10)
     }{
        document.getElementById("container").innerHTML += messageHigh2;
        }
    {
        if (age=>10 && sugar =>10)
    }{
        document.getElementById("container").innerHTML += messageHigh3;
        }
    {
        if (bmi=>10 && family =>10)
    }{      
        document.getElementById("container").innerHTML += messageHigh4;
        }
    {
        if (bmi=>10 && sugar =>10)
    }{      
        document.getElementById("container").innerHTML += messageHigh5;
        }
    {   
        if (family=>10 && sugar =>10)
    }{      
        document.getElementById("container").innerHTML += messageHigh6;
        }
   else
    {
     break;
    }
}
奥萨吉·阿格多(Osagui Aghedo)

这是您的代码应如下所示:

if( total >= 0 && total <= 15){

    document.getElementById("container").innerHTML += messageLow;

}else if(total >= 16 && total <= 25){

    document.getElementById("container").innerHTML += messageMed;

}else if(total > 25){

    if (age>=10 && bmi >=10){

      document.getElementById("container").innerHTML += messageHigh1;

    }else if(age>=10 && family >=10){

      document.getElementById("container").innerHTML += messageHigh2;

    }else if (age>=10 && sugar >=10) {

    document.getElementById("container").innerHTML += messageHigh3;

    }else if (bmi>=10 && family >=10){ 

    document.getElementById("container").innerHTML += messageHigh4;

    }else if (bmi>=10 && sugar >=10){  

    document.getElementById("container").innerHTML += messageHigh5;

    }else if (family>=10 && sugar >=10){ 

    document.getElementById("container").innerHTML += messageHigh6;

    }

}

请注意,您仅将break用于循环或switch语句。您无需输入“;” 在if语句之后。它称为“条件”,而不是参数。参数被传递给函数。并且您不输入“;” 条件或条件之后的代码(“ {}”内的代码)将始终执行,即使不满足条件也是如此;

是“> =”而不是“ =>”

是“ else if”而不是“ elseif”

希望这对您有所帮助:)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

链接到 MediaWiki 中的外部 HTML 页面

来自分类Dev

使用localStorage在页面之间传递变量并在链接中传递变量

来自分类Dev

在Wordpress中动态链接到页面

来自分类Dev

在Wordpress中动态链接到页面

来自分类Dev

Jekyll-链接到页面中的帖子

来自分类Dev

链接到Wagtail CMS中的特定页面

来自分类Dev

在消息框中显示if语句变量

来自分类Dev

静态创建的Html表链接字段值单击重定向并在java中的另一个页面中显示那些对应的值

来自分类Dev

将新的Class()和函数链接到JavaScript中的相同变量?

来自分类Dev

将用户输入从HTML页面传递到Perl脚本并在网页中显示结果

来自分类Dev

链接到应用商店,并在应用名称中添加“空格”

来自分类Dev

通过下拉菜单链接到HTML中的其他页面

来自分类Dev

将bootstrap.css文件链接到Play框架中的scala.html页面

来自分类Dev

将样式表链接到C#WPF应用程序中的本地html页面

来自分类Dev

SED语句替换Shell脚本中的变量

来自分类Dev

将链接作为php中的变量传递并在html上回显

来自分类Dev

编辑成功消息并在Opencart / Mijoshop中链接

来自分类Dev

将新节点链接到c中的链接列表的问题

来自分类Dev

将新节点链接到c中的链接列表的问题

来自分类Dev

var.push并在html页面中显示我的新临时信息

来自分类Dev

无法链接到html中的外部javascript

来自分类Dev

使用脚本(按钮)在 HTML 中的新选项卡中打开链接

来自分类Dev

链接到外部页面并将其HTML自动添加到原始页面的包装器中

来自分类Dev

直接链接到特定的聊天或消息中吗?

来自分类Dev

带有 IF 语句的 R 中的新变量

来自分类Dev

停止页面加载并在内容脚本中重定向

来自分类Dev

在一个脚本中创建变量并在另一个脚本中使用。jQuery/HTML/JS

来自分类Dev

链接到Cordova应用程序中的评论页面

来自分类Dev

链接到Rails App中页面上的锚点

Related 相关文章

  1. 1

    链接到 MediaWiki 中的外部 HTML 页面

  2. 2

    使用localStorage在页面之间传递变量并在链接中传递变量

  3. 3

    在Wordpress中动态链接到页面

  4. 4

    在Wordpress中动态链接到页面

  5. 5

    Jekyll-链接到页面中的帖子

  6. 6

    链接到Wagtail CMS中的特定页面

  7. 7

    在消息框中显示if语句变量

  8. 8

    静态创建的Html表链接字段值单击重定向并在java中的另一个页面中显示那些对应的值

  9. 9

    将新的Class()和函数链接到JavaScript中的相同变量?

  10. 10

    将用户输入从HTML页面传递到Perl脚本并在网页中显示结果

  11. 11

    链接到应用商店,并在应用名称中添加“空格”

  12. 12

    通过下拉菜单链接到HTML中的其他页面

  13. 13

    将bootstrap.css文件链接到Play框架中的scala.html页面

  14. 14

    将样式表链接到C#WPF应用程序中的本地html页面

  15. 15

    SED语句替换Shell脚本中的变量

  16. 16

    将链接作为php中的变量传递并在html上回显

  17. 17

    编辑成功消息并在Opencart / Mijoshop中链接

  18. 18

    将新节点链接到c中的链接列表的问题

  19. 19

    将新节点链接到c中的链接列表的问题

  20. 20

    var.push并在html页面中显示我的新临时信息

  21. 21

    无法链接到html中的外部javascript

  22. 22

    使用脚本(按钮)在 HTML 中的新选项卡中打开链接

  23. 23

    链接到外部页面并将其HTML自动添加到原始页面的包装器中

  24. 24

    直接链接到特定的聊天或消息中吗?

  25. 25

    带有 IF 语句的 R 中的新变量

  26. 26

    停止页面加载并在内容脚本中重定向

  27. 27

    在一个脚本中创建变量并在另一个脚本中使用。jQuery/HTML/JS

  28. 28

    链接到Cordova应用程序中的评论页面

  29. 29

    链接到Rails App中页面上的锚点

热门标签

归档