English 中文(简体)
比较 j的两箱子价值
原标题:Strange behavior on comparing two select boxes values in jQuery
  • 时间:2011-09-01 08:25:07
  •  标签:
  • jquery

传真:

<html>
    <body>
        <select class="FormInput" id="minheight" style="width: 120px;" name="minheight">
    <option selected="selected" value="">- Select -</option>
    <option value=1>4  0" (1.22 mts)</option>
    <option value=2>4  1" (1.24 mts)</option>
    <option value=3>4  2" (1.28 mts)</option>
    <option value=4>4  3" (1.31 mts)</option>
    <option value=5>4  4" (1.34 mts)</option>
    <option value=6>4  5" (1.35 mts)</option>
    <option value=7>4  6" (1.37 mts)</option>
    <option value=8>4  7" (1.40 mts)</option>
    <option value=9>4  8" (1.42 mts)</option>
    <option value=10>4  9" (1.45 mts)</option>
    <option value=11>4  10" (1.47 mts)</option>
    <option value=12>4  11" (1.50 mts)</option>
    <option value=13>5  0" (1.52 mts)</option>
    <option value=14>5  1" (1.55 mts)</option>
    <option value=15>5  2" (1.58 mts)</option>
    <option value=16>5  3" (1.60 mts)</option>
    <option value=17>5  4" (1.63 mts)</option>
    <option value=18>5  5" (1.65 mts)</option>
    <option value=19>5  6" (1.68 mts)</option>
    <option value=20>5  7" (1.70 mts)</option>
    <option value=21>5  8" (1.73 mts)</option>
    <option value=22>5  9" (1.75 mts)</option>
    <option value=23>5  10" (1.78 mts)</option>
    <option value=24>5  11" (1.80 mts)</option>
    <option value=25>6  0" (1.83 mts)</option>
    <option value=26>6  1" (1.85 mts)</option>
    <option value=27>6  2" (1.88 mts)</option>
    <option value=28>6  3" (1.91 mts)</option>
    <option value=29>6  4" (1.93 mts)</option>
    <option value=30>6  5" (1.96 mts)</option>
    <option value=31>6  6" (1.98 mts)</option>
    <option value=32>6  7" (2.01 mts)</option>
    <option value=33>6  8" (2.03 mts)</option>
    <option value=34>6  9" (2.06 mts)</option>
    <option value=35>6  10" (2.08 mts)</option>
    <option value=36>6  11" (2.11 mts)</option>
    <option value=37>7  (2.13 mts) plus</option>
    </select> &nbsp; to &nbsp;
    <select class="FormInput" id="maxheight" style="width: 120px;" name="maxheight">
    <option selected="selected" value="">- Select -</option>
    <option value=1>4  0" (1.22 mts)</option>
    <option value=2>4  1" (1.24 mts)</option>
    <option value=3>4  2" (1.28 mts)</option>
    <option value=4>4  3" (1.31 mts)</option>
    <option value=5>4  4" (1.34 mts)</option>
    <option value=6>4  5" (1.35 mts)</option>
    <option value=7>4  6" (1.37 mts)</option>
    <option value=8>4  7" (1.40 mts)</option>
    <option value=9>4  8" (1.42 mts)</option>
    <option value=10>4  9" (1.45 mts)</option>
    <option value=11>4  10" (1.47 mts)</option>
    <option value=12>4  11" (1.50 mts)</option>
    <option value=13>5  0" (1.52 mts)</option>
    <option value=14>5  1" (1.55 mts)</option>
    <option value=15>5  2" (1.58 mts)</option>
    <option value=16>5  3" (1.60 mts)</option>
    <option value=17>5  4" (1.63 mts)</option>
    <option value=18>5  5" (1.65 mts)</option>
    <option value=19>5  6" (1.68 mts)</option>
    <option value=20>5  7" (1.70 mts)</option>
    <option value=21>5  8" (1.73 mts)</option>
    <option value=22>5  9" (1.75 mts)</option>
    <option value=23>5  10" (1.78 mts)</option>
    <option value=24>5  11" (1.80 mts)</option>
    <option value=25>6  0" (1.83 mts)</option>
    <option value=26>6  1" (1.85 mts)</option>
    <option value=27>6  2" (1.88 mts)</option>
    <option value=28>6  3" (1.91 mts)</option>
    <option value=29>6  4" (1.93 mts)</option>
    <option value=30>6  5" (1.96 mts)</option>
    <option value=31>6  6" (1.98 mts)</option>
    <option value=32>6  7" (2.01 mts)</option>
    <option value=33>6  8" (2.03 mts)</option>
    <option value=34>6  9" (2.06 mts)</option>
    <option value=35>6  10" (2.08 mts)</option>
    <option value=36>6  11" (2.11 mts)</option>
    <option value=37>7  (2.13 mts) plus</option>
    </select>
    <span></span>
    </body>
</html>

The CSS:

.form-error { color:red; font-size:12px;}
.form-info { color:#B1B1B1; font-size:12px;}
.form-ok { color:green; font-size:12px; }

和文本:

var minheight = $("#minheight");
var maxheight = $("#maxheight");
maxheight.blur(validatemaxheight);

$( #minheight,#maxheight ).change(function(){  
        heightvalidate();
    });

function validatemaxheight()
    {
        heightvalidate();
    }

function heightvalidate()
    {
        console.log( minheight::  +minheight.val()+     maxheight::  +maxheight.val());
        if(minheight.val() > maxheight.val())
        {
            minheight.parent().find( span ).attr("class","form-error").html("Minimum height should not be greater than maximum height.");    
            minheight.focus();
            return false;
        }
        else if(minheight.val() == maxheight.val())
        {
            minheight.parent().find( span ).attr("class","form-error").html("Minimum height should be less than maximum height.");    
            minheight.focus();
            return false;
        }
        else
        {
            minheight.parent().find( span ).attr("class","form-ok").html( OK );
            return true;
        }    
    }

我实际上比较了最低高度和最高高度。 如果是矿砂;最高高度,就会发现错误信息。

The above condition works fine until if choose the minheight value above 9 and maxheight value greater than 9, which is greater than min height. Even though the minheight < maxheight, still the error message shows that the minheight is greater than maxheight.

The live version here: http://jsfiddle.net/prajan55/u9NJD/

Any help appreciated..

问题回答

在比较这些数值之前,将这些数值实际比较为数字而不是图象。

我认为,这是因为检查是在扼杀而不是ger,因此,你必须首先使用 par(18.val())”和“ par(最大)”进行消化。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签