我有這個基本的自動完成JavaScript,效果很好,但您需要對網頁進行硬編碼。我正在試圖做的是用Perl腳本將變量傳遞給自動完成JavaScript
工作的JavaScript代碼看起來像這樣的「自動完成」可變數據發送到頁面:
var CustomArray = new Array('an apple','alligator','elephant','pear','kingbird',
'kingbolt','kingcraft','kingcup','kingdom','kingfisher',
'kingpin','SML');
現在新的代碼是:
var CustomArray=new Array(Autocomplete);
而且Perl腳本是將數據發送回瀏覽器看起來像這樣:
var Autocomplete = 'an apple','alligator','elephant','pear','kingbird',
'kingbolt','kingcraft','kingcup','kingdom','kingfish er','kingpin','SML'
我也試過
var Autocomplete = ['an apple','alligator','elephant','pear','kingbird',
'kingbolt','kingcraft','kingcup','kingdom','kingfisher',
'kingpin','SML']
但我得到:在自動完成'an apple','alligator','elephant','pear','kingbird','kingbolt','kingcraft','kingcup','kingdom','kingfish er','kingpin','SML'
所有作爲一個字符串。
我似乎無法讓它正常工作。完整的HTML代碼如下。
<html>
<head>
<script language="javascript" type="text/javascript" src="http://www.comicinvasion.com/Code/Java/Autocomplete/Autocomplete.js"></script>
<script language="javascript" type="text/javascript" src="http://www.comicinvasion.com/Code/Java/Autocomplete/Common.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="http://www.ComicInvasion.com/cgi-bin/Autocomplete.pl"></script>
<script>
var CustomArray=new Array(Autocomplete);
</script>
</head>
<body>
<input type='text' style='font-family:verdana;width:300px;font-size:12px' id='ACMP' value=''/>
<script>
var obj = actb(document.getElementById('ACOMP'),CustomArray);
</script>
</body>
</html>
看起來就像是在輸入錯誤。該ID感謝您的幫助! – Blnukem 2011-12-21 12:28:42