如何使用ajax捕获鼠标离开值

时间:2016-09-26 08:20:53

标签: php

我使用jquery价格滑块根据价格范围对数据进行排序。在这种情况下,直接声明最小值和最大值。但是,现在我需要更改此方法。现在,我希望通过更改滑块范围来获得结果。(而不是通过单击“查找”按钮)。那么,如何从价格范围滑块中捕获鼠标离开值(最小值和最大值)。这是我的代码,     

include('db.php');
    if($_POST)
    {
        mysqli_real_escape_string($connection,$_POST['amount']);
        $values = str_replace(' ','',$_POST['amount']);
        $values = str_replace('$','',$values);
        $values = explode('-',$values);
        $min = $values[0];
        $max = $values[1];
        $res = mysqli_query($connection,'select id,product,price, DATE_FORMAT(date,"%D %b-%Y") as date from products where price BETWEEN "'.$min.'" AND "'.$max.'"');
        $count  =   mysqli_num_rows($res);
        $HTML='';
        if($count > 0)
        {
            while($row=mysqli_fetch_array($res))
            {
                $id         = $row['id'];
                $product    = $row['product'];
                $price      = $row['price'];
                $date       = $row['date'];

            $HTML .= '<div>';
            $HTML .= 'Product ID: '.$id;
            $HTML .= '<br />Product Name: '.$product;
            $HTML .= '<br />Price: <strong>$'.$price.'</strong> Posted on: '.$date;
            $HTML .= '</div><br /><hr />';
        }
    }
    else
    {
        $HTML='No Data Found';
    }
}
else
{
    $min = 30;
    $max = 700;
    $HTML='Search Products in range.';
}

?>
this is my script

    <script type="text/javascript">
    $(function() {
        $( "#slider-range" ).slider({
          range: true,
          min: 0,
          max: 1000,
          values: [ <?php echo $min; ?>, <?php echo $max; ?> ],
          slide: function( event, ui ) {
            $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
          }
        });
        $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
          " - $" + $( "#slider-range" ).slider( "values", 1 ) );
      });
    </script>
    <body>
        <div>

1 个答案:

答案 0 :(得分:0)

使用mouseleave()jQuery函数。 请阅读此处的文档:https://api.jquery.com/mouseleave/