这是我的自动完成1.autocomplete.js级联样式表的jquery文件 2.autocomplete.css和图片放大镜 3.autocomplete.gif
HTML& JavaScript代码:
<input type = 'textbox' id='vendor' name = 'vendor' maxlength='70'>
<input name="h_vendor" type="hidden" id="h_vendor" value=""/>
function make_autocom(autoObj,showObj){
var mkAutoObj=autoObj;
var mkSerValObj=showObj;
new Autocomplete(mkAutoObj, function() {
this.setValue = function(id) {
document.getElementById(mkSerValObj).value = id;
}
if ( this.isModified )
this.setValue("");
if ( this.value.length < 1 && this.isNotClick )
return ;
return "auto_vendor.php?q=" +encodeURIComponent(this.value);
});
}
make_autocom("vendor","h_vendor");
文件auto_vendor.php:
$q = urldecode($_GET["q"]);
$pagesize = 5;
$table_db="buy";
$find_field="vendor";
$sql = "select distinct vendor from $table_db where locate('$p', $find_field) > 0 and division = \"".$_SESSION['chk_division']."\" order by locate('$p', $find_field), $find_field limit $pagesize";
$results = mysql_query($sql);
while ($row = mysql_fetch_assoc( $results )) {
$id = $row["vendor"];
$name = $row["vendor"];
$name = str_replace("'", "'", $name);
if($q!=""){
$display_name = preg_replace("?(" . $q . ")?i", "<b>$1</b>", $name);
}else{
$display_name = $name;
}
echo "<li onselect=\"this.setText('$name').setValue('$id');\">$display_name</li>";
}
虽然使用(&#34;)或(&#39;)自动完成功能,但无法将结果输入文本框。
http://resource.thaicreate.com/upload/stock/20151117044401.jpg?v=1001