jquery自动完成根据数据库的值更改背景颜色

jquery自动完成根据数据库的值更改背景颜色,jquery,autocomplete,Jquery,Autocomplete,当数据库中的产品数小于或等于1时,我想更改列表的背景色。这很好,只是不知道如何更改背景 <input type="text" value="" id="mercaderia" > $("#mercaderia").autocomplete({ source: "autocompletemer.php", minLength: 2, html: 'html', focus: function(event, ui) {

当数据库中的产品数小于或等于1时,我想更改列表的背景色。这很好,只是不知道如何更改背景

<input type="text" value=""  id="mercaderia"   >


$("#mercaderia").autocomplete({
     source: "autocompletemer.php",         
     minLength: 2,
     html: 'html',
     focus: function(event, ui) {
            // prevent autocomplete from updating the textbox
            //event.preventDefault();
            // manually update the textbox
            //$(this).val(ui.item.label);
        },
     select: function(event, ui) {
            // prevent autocomplete from updating the textbox
            //event.preventDefault();
            // manually update the textbox and hidden field
            //$(this).val(ui.item.label);
            //$("#autocomplete2-value").val(ui.item.value);
        }               
});
我们的目标是实现和平 我试着从php来做,但不适合

<?php
//defino una clase que voy a utilizar para generar los elementos sugeridos en autocompletar
class ElementoAutocompletar {
   var $value;
   var $label;

   function __construct($label, $value){
      $this->label = $label;
      $this->value = $value;
   }
}

//recibo el dato que deseo buscar sugerencias
$datoBuscar = $_GET["term"];

//conecto con una base de datos
$conexion = mysql_connect("localhost", "root", "");
mysql_select_db("base_ropa");

//busco un valor aproximado al dato escrito
$ssql = "SELECT id, titulo, precio, cantidad FROM mercaderia WHERE titulo LIKE '%" . $datoBuscar . "%' LIMIT 10";
$rs = mysql_query($ssql);

//creo el array de los elementos sugeridos
$arrayElementos = array();

//bucle para meter todas las sugerencias de autocompletar en el array
while ($fila = mysql_fetch_array($rs)){
    $temp = $fila["titulo"].":".str_replace('.',',',$fila[precio]).":".$fila[cantidad];

    $t = explode(":", $temp);
    if ($t[2] <= 1) {
        $temp1 = str_replace(strtolower($datoBuscar), '<span style="background-color:red">"<b class="ot4">'.$datoBuscar.'</b>', '<b>'.strtolower($t[0]).' - &lt;</b>');     
        $temp = str_replace('&lt;', '<span class="ot2"> $'.$t[1].'</span></span>', $temp1);
    }else {
        $temp1 = str_replace(strtolower($datoBuscar), '<b class="ot">'.$datoBuscar.'</b>', '<b>'.strtolower($t[0]).' - &lt;</b>');      
        $temp = str_replace('&lt;', '<span class="ot2"> $'.$t[1].'</span>', $temp1);
    }

            //$respuesta .= "<li style='background-color: #FFDDDD;'>".$temp."</li>";
        //else
            //$respuesta .= "<li>".$temp."</li>";



    array_push($arrayElementos, new ElementoAutocompletar($temp, $fila["titulo"].' - $'.$fila["precio"])); //$fila["id"]
}

print_r(json_encode($arrayElementos));
?>
这是不安全的: $datoBuscar=$_GET[term]

$ssql=从mercaderia中选择id、titulo、precio、cantidad,其中titulo类似“%”$达托布斯卡。%'限制10


这并不能回答您最初的问题,但这段代码可能会被泄露。

我知道,这只是本地交易。没有网络;