使用自动完成 javascript:
<link rel="stylesheet" type="text/css" href="j query/js/jquery.autocomplete.css" />
<script type="text/javascript" src="j query/js/jquery.autocomplete.js"></script>{/literal}
<script type="text/javascript">
$().ready(function() {
$(".id_perkiraan").autocomplete("j query/js/cari.php",{width:350, max:28, scroll:false });
});
</script>
html:
<tr>
<td width="75">
<div class="demo">
<div>
<p><input type="text" name="id_perkiraan[]" class="id_perkiraan" size=75 autocomplete="off"></p>
</div>
</div>
<div class="pilihan"></div>
</td>
<td><input type ='text' name='keterangan[]' size="20"></td>
<td><input type ='text' name='debet[]' size="20" ></td>
<td><input type ='text' name='kredit[]' size="20" ></td>
</tr>
<tr>
<td width="75">
<div class="demo">
<div>
<p><input type="text" name="id_perkiraan[]" class="id_perkiraan" size=75 autocomplete="off"></p>
</div>
</div>
<div class="pilihan"></div>
</td>
<td><input type ='text' name='keterangan[]' size="20"></td>
<td><input type ='text' name='debet[]' size="20" ></td>
<td><input type ='text' name='kredit[]' size="20" ></td>
</tr>
和 cari.php :
<?
mysql_connect("localhost","root","root");
mysql_select_db("siakud");
$q = strtolower($_GET["q"]);
if (!$q) return;
$query = mysql_query("select * from perkiraan where id_perkiraan LIKE '%$q%'");
while($r = mysql_fetch_array($query))
{
$id = $r['id_perkiraan'];
$nama = $r['nama'];
echo "$id [$nama] \n";
}
?>
但不知何故,只有一个“id_perkiraan”文本字段具有自动完成功能……第二个、第三个 adn 等“id_perkiraan”怎么样???