0

我想检查我的应用程序的按钮是否被按下。我面临的错误是,即使单击按钮,所有警报也会显示。附上代码片段,通过点击按钮设置变量。

如果选择了任何值,我希望不显示警报,

var condition ; 
var clickable;     // GLOBAL VARIABLES

function clickMe1() 
{
    clickable = "Sell";
}

function clickMe2() 
{
    clickable = "Rent";
}

function condition1()
{
    condition="Excellent"
}

function condition2()
{
    condition="Good"
}

function condition3()
{
    condition="Fair"
}

function condition4()
{
    condition="New"
}



function display()    
{
    if (condition != "Excellent"||"New"||"Fair"||"Good")
    {
        alert( " Please enter the condition ");
    }
    if (clickable != "Sell"||"Rent")
    {
        alert("Please enter the Sell");
    }
    if (costSell === '')  
    {
        alert("Please select a Price ");
    }
    if ((condition === "Excellent"||"New"||"Fair"||"Good") && (clickable === "Selling"||"leasing")&&(!isNaN(costSell)))
    {
        // Do Something
    },
    error: function(data){
        console.log("not added");
    }
    });
    }
    else
    {
        alert(" price is not a number"); 
    }
}

我也试过:

if(condition !='Excellent'|| condition!='New' || condition!='Fair'|| condition!='Good')
{
    alert( " Please enter the condition ");
}
if (clickable !='Sell'||'Rent' )
{
    alert("Please enter the Sell ");
4

3 回答 3

2
于 2012-08-14T01:54:58.607 回答
0

condition !="Excellent"||"New"||"Fair"||"Good"

Conditions like this are your problem.

condition !="Excellent" && condition != "New" ...

^The solution

于 2012-08-14T01:55:34.103 回答
0

Your problem is you're testing multiple conditions without repeating the left-hand operand.

For example:

condition !="Excellent"||"New"||"Fair"||"Good"

It should be this:

condition != "Excellent" || condition != "New" || condition != "Fair" || condition !="Good"
于 2012-08-14T01:55:54.790 回答