如果语句和条件
问题描述:
我想在alert框中确认两个不同的事情,如果语句。首先是用户按下了“是”按钮,第二个是用户在页面上的输入值。请参阅下面的代码。我仍然非常绿色,任何帮助将不胜感激。如果语句和条件
var cMsg = "You are about to reset this page!";
cMsg += "\n\nDo you want to continue?";
var nRtn = app.alert(cMsg,2,2,"Question Alert Box");
if(nRtn == 4) && (getField("MV").value == 5)
{
////// do this
}
else if(nRtn == 4) && (getField("MV").value == 6)
{
/////then do this
}
else if(nRtn == 4) && (getField("MV").value == 7)
{
/////then do this
}
}
else if(nRtn == 3)
{
console.println("Abort the submit operation");
}
else
{ //Unknown Response
console.println("The Response Was somthing other than Yes/No: " + nRtn);
}
答
您的if...else语法不正确。正确的语法
if (condition)
statement1
[else
statement2]
使用正确的语法
if (nRtn == 4 && getField("MV").value == 5) {
////// do this
} else if (nRtn == 4 && getField("MV").value == 6) {
/////then do this
} else if (nRtn == 4 && getField("MV").value == 7) {
/////then do this
} else if (nRtn == 3) {
console.println("Abort the submit operation");
} else { //Unknown Response
console.println("The Response Was somthing other than Yes/No: " + nRtn);
}
而不是
if (nRtn == 4) && (getField("MV").value == 5) {
////// do this
} else if (nRtn == 4) && (getField("MV").value == 6) {
/////then do this
} else if (nRtn == 4) && (getField("MV").value == 7) {
/////then do this
} <=== Remove this
} else if (nRtn == 3) {
console.println("Abort the submit operation");
} else { //Unknown Response
console.println("The Response Was somthing other than Yes/No: " + nRtn);
}
答
你试图评估两种不同的条件是: “NRTN” //值从app.alert返回(cMsg,2,2,“问题提示框”); : 和:getField(“MV”).value。
但是,编译器将只处理第一个条件,因为大括号在那里结束。您应该确保将大括号内的所有条件都括起来。个别条件可以并且按照惯例也应该在主支架内分开的大括号中。 因此正确的方法应该是:
if ((nRtn == 4) && (getField("MV").value == 5))
//notice the initial if ((and terminating))
//You could have 3 conditions as follows
// if (((condition1) && (condition2)) && (condition3)))
{
////// do this
}
else if((nRtn == 4) && (getField("MV").value == 6))
{
/////then do this
}
else if((nRtn == 4) && (getField("MV").value == 7))
{
/////then do this
}
}
else if(nRtn == 3)
{
console.println("Abort the submit operation");
}
else
{ //Unknown Response
console.println("The Response Was somthing other than Yes/No: " + nRtn);
}
您的问题是? – Teemu 2015-02-06 05:16:14
不正确的语法首先更正,使用'if((nRtn == 4)&&(getField(“MV”)。value == 5))'如果语法是'if(condition)....' – Satpal 2015-02-06 05:16:29
@Satpal这就是我在找什么......谢谢 – 2015-02-06 06:51:36