2016-09-26 23 views
-2

我正在使用jquery價格滑塊來排序基於價格範圍的數據。在這種情況下,最小值和最大值直接聲明。但現在我需要改變這種方法。現在,我想通過更改滑塊範圍來獲得結果(不是通過單擊查找按鈕)。那麼,如何從價格範圍滑塊中捕獲鼠標離開值(最小值和最大值)。這是我的代碼, 我怎樣才能捕獲鼠標使用ajax離開值

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> 

+0

我認爲[this](https://api.jquery.com/mouseleave/)就是您要找的。 – Andrew

+0

我嘗試獲取最小值和最大值之間的酒店價格詳細信息。當用戶離開鼠標指針時,結果將顯示。但我不知道ajax很好。我很困惑如何在此代碼中獲取ajax .. – user6085744

回答