0
我想讓自動完成功能在我正在製作的網站應用程序上工作。我已經將我的代碼剝離到最基本的要領,但仍然無法實現。我從http://www.phpguru.org/static/AutoComplete.html獲得源文件,並且盡我所能在他們的網站演示中完全實現了他們的做法。我的測試代碼如下:在JavaScript自動完成時遇到問題
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>test</title>
</head>
<body>
<script language="javascript" type="text/javascript" src="/Management/AutoComplete.js"></script>
<div id="content">
<script type="text/javascript">
if (location.href.indexOf('/JavaScripts/AutoComplete') != -1) {
window.onload = function(){
data = ['Joes Plumbing1','Joes Plumbing2','Joes Plumbing3','Joes Plumbing4'].sort();
AutoComplete_Create('customers', data);
}
}
</script>
<form id="form" action="" method="post">
<table border="0">
<tr>
<td>Customer Search</td>
</tr>
<tr>
<td><input type="text" id="customers"/></td>
</tr>
</table>
</form>
</div>
</body>
</html>
這是一個有點回地面的信息,可以幫助你幫助我:
我的服務器正常工作與其他.js
文件。
我複製並粘貼了AutoComplete.js
(不是AutoComplete.old.js
)文件,我從上面提到的網站下載的,根本沒有碰它。
爲什麼不能正常工作?
你得到了什麼樣的錯誤? – 2010-06-25 06:10:55
完全沒有錯誤。頁面源代碼(來自瀏覽器)也很好看,或者至少我看不到任何問題。我的頁面使用搜索欄生成,但是當我鍵入它或雙擊它時,不會發生自動完成功能。 – ubiquibacon 2010-06-25 06:14:36
if location.href.indexOf('/ JavaScripts/AutoComplete')!= -1) - 這意味着您的自動填充頁面的網址必須包含指定的字符串。可以? – Goran 2010-06-25 06:27:03