JavaScript if()语句未按预期进行评估

mar*_*rky 1 javascript comparison-operators

我有一个jsFiddle来证明我的问题(并允许你们把我拉直).

我只是检查两个输入文本框的值,并在最高价格低于最低价格时提醒用户,但他们正在向后评估!我有,(maxValue < minValue)...但它评估它,就好像操作符"大于".

我错过了什么?!?

<form id="search" action="search.php" method="post">

    <label id="lblPriceMin" for="txtPriceMin">Minimum Price</label>
    <input type="text" id="txtPriceMin" name="priceMin"></input>
    <br />
    <br />

    <label id="lblPriceMax" for="txtPriceMax">Maximum Price</label>
    <input type="text" id="txtPriceMax" name="priceMax"></input>
    <br />
    <br />

    <input type="reset" id="reset" name="reset" value="Clear Form" />
</form>
Run Code Online (Sandbox Code Playgroud)

这是js,

$('#txtPriceMax').focusout(function() {

    var minValue = $('input#txtPriceMin').val();
    var maxValue = $('input#txtPriceMax').val();

    //alert ('minValue: ' + minValue + ', maxValue: ' + maxValue);

    if (maxValue < minValue) {
        alert ('The maximum value (' + maxValue + ') must be greater than the minimum value (' + minValue + ')!');
    }
});
Run Code Online (Sandbox Code Playgroud)

Gab*_*abe 8

使用 parseFloat()

jsFiddle示例

if (parseFloat(maxValue) < parseFloat(minValue)) 
Run Code Online (Sandbox Code Playgroud)