Php Ajax结果与预期不符

Php Ajax结果与预期不符,php,jquery,ajax,Php,Jquery,Ajax,我有一个Ajax查询,它得到一个result=total。 然后,它用于根据用户输入显示图像。 有两个阈值-黄色和红色,带有输入框,用户在其中为每个阈值设置限制 我的Ajax查询输入了正确的数字,但这段代码并没有按照我的意愿显示图像。当超过红色阈值时,黄色按钮始终为默认值,红色按钮从不显示 我想要的是: If < yellow threshold = show vote_btn If >= yellow threshold && < red threshold

我有一个Ajax查询,它得到一个result=total。 然后,它用于根据用户输入显示图像。 有两个阈值-黄色和红色,带有输入框,用户在其中为每个阈值设置限制

我的Ajax查询输入了正确的数字,但这段代码并没有按照我的意愿显示图像。当超过红色阈值时,黄色按钮始终为默认值,红色按钮从不显示

我想要的是:

If < yellow threshold = show vote_btn
If >= yellow threshold && < red threshold = show yellow_btn
Else = show red_btn
我的实际代码:

First threshold:
<input id="threshold_yellow" type="number" size="3" style="width: 3.5em;" value="" />
<br /><br /> 
Second threshold:
<input id="threshold_red" type="number" size="3" style="width: 3.5em;" value="" />
<br /><br />    
<div>total votes: <span id="output" style="font-weight: bold;">loading...</span></div>
<div id="graphic">
<img id="pic1" src="vote_btn.png" style="display: none;"/>
<img id="pic2" src="yel_btn.jpeg"  style="display: none;"/>
<img id="pic3" src="red_btn.png"  style="display: none;"/>
</div>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
     function update() 
    {
            $.ajax({
                url: 'simcon.php',
                type: 'GET',
        dataType: 'json',
                success: function(data)
        {
                    var total = data[0];
        $('#output').html(total);

        // Toggle graphic based on total's value.


        if (total < $('#threshold_yellow').val())
        {
            //$('#graphic').children().hide();
            $('#pic1').show();
        }
        else if (total < $('#threshold_red').val() || total >= $('#threshold_yellow').val())
        {   //$('#graphic').children().hide();
            $('#pic2').show();
        } 
        else
        {   //$('#graphic').children().hide();
            $('#pic3').show();
        } 
        }
            });        
         }
尝试对整数值使用parseInt,或对双精度值使用parseFloat

if (parseInt(total) < parseInt($('#threshold_yellow').val()))
{
   //$('#graphic').children().hide();
   $('#pic1').show();
}
else if (parseInt(total) < parseInt($('#threshold_red').val()) || parseInt(total) >= parseInt($('#threshold_yellow').val()))
{   
   //$('#graphic').children().hide();
   $('#pic2').show();     
} 
else
{  
   //$('#graphic').children().hide();
   $('#pic3').show();
} 

您已将css放在图像中作为显示:无

所以你必须写这篇文章来展示图像

$'pic1'.css'display','block'

而不是$pic1.show