请您能帮我获取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;
}
}
这是您的代码应如下所示:
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] 删除。
我来说两句