0
我正在嘗試創建一個頁面,其中包含120個自動完成txtboxes,以便在我的索引頁和我的 js頁面中創建一個循環。可是,我似乎去錯JQuery自動完成錯誤
var a = "#A" + i;
var b = "#B" + i;
var c = "#C" + i;
$(a).html(thehtml);
$(b).html(thehtml2);
$(c).html(thehtml3);
,但如果我的代碼
var a = "#A1";
var b = "#B1";
var c = "#C1";
$(a).html(thehtml);
$(b).html(thehtml2);
$(c).html(thehtml3);
第一自動完成框可以完美運行,但其餘的不工作,因爲他們有不同的ID
索引頁
<!doctype html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="stylesheet" type="text/css" media="all" href="style.css">
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery.autocomplete.min.js"></script>
<script type="text/javascript" src="js/currency-autocomplete.js"></script>
</head>
<body>
<div id="w">
<div id="content">
<h1>Folders</h1>
<div id="searchfield">
<table>
<th>Folder art</th>
<th>Artnr</th>
<th>zoekterm</th>
<th>Omschrijving</th>
<th>BTW</th>
<?php
//teller defineren
$i=0;
$id=1;
while($i<120)
{
$id_name="autocomplete".$id;
$A="A".$id;
$B="B".$id;
$C="C".$id;
if($id < 10)
{$art="FS000".$id;}
else if($id < 100)
{$art="FS00".$id;}
else
{$art="FS0".$id;}
echo "<tr>";
echo "<td><input type=\"text\" name=\"$art\" value=\"$art\" size=\"10\"></td>";
echo "<td><div id=\"$B\"></div></td>";
echo "<td><input type=\"text\" name=\"$id_name\" id=\"$id_name\"></td>";
echo "<td><div id=\"$A\"></div></td>";
echo "<td><div id=\"$C\"></div></td>";
$id++;
$i++;
}
?>
</table>
</div>
</body>
</html>
代碼自動完成.js文件
$(function(){
var currencies = [
{ value: 'Afghan afghani', data: 'AFN',BTW: '2' },
{ value: 'Albanian lek', data: 'ALL',BTW: '2' },
{ value: 'Algerian dinar', data: 'DZD',BTW: '2' },
{ value: 'European euro', data: 'EUR',BTW: '2' },
{ value: 'Angolan kwanza', data: 'AOA',BTW: '4' },
{ value: 'East Caribbean dollar', data: 'XCD',BTW: '4' },
{ value: 'Argentine peso', data: 'ARS',BTW: '2' },
{ value: 'Armenian dram', data: 'AMD',BTW: '2' },
{ value: 'Aruban florin', data: 'AWG',BTW: '2' },
{ value: 'Australian dollar', data: 'AUD',BTW: '4' },
{ value: 'Azerbaijani manat', data: 'AZN',BTW: '8' },
];
var z = "#autocomplete";
var id=1;
var i=0;
var aantal=120;
for (var i = 1; i < 120; i++){
$(z + id).autocomplete({
lookup: currencies,
onSelect: function (suggestion) {
var thehtml='<input type=\"text\" value=\"'+ suggestion.value + '\">';
var thehtml2='<input type=\"text\" value=\"'+ suggestion.data + '\" size=\"10\">';
var thehtml3='<input type=\"text\" value=\"'+ suggestion.BTW + '\" size=\"5\">';
var a = "#A" + i;
var b = "#B" + i;
var c = "#C" + i;
$(a).html(thehtml);
$(b).html(thehtml2);
$(c).html(thehtml3);
}
});
id++;}
});
什麼是錯誤? 結果正常代碼 結果改變代碼
哪裏出錯?顯示的錯誤是什麼?如果你把html放在單引號中,那麼爲什麼你需要用'\「'來雙引號呢?你總是可以使用''」「''... – j809