我的代码看起来像
<div class="my-form">
<p class="text-box">
<input type="text" class="form-control" name="boxes[]" id="Name" value="" placeholder="Name" onchange="javascript:callid(this.id);" />
<input type="text" class="form-control" name="boxes[]" value="" id="box1" placeholder="Stripes" />
<a class="add-box" href="#">Add More</a>
</p>
</div>
<script type="text/javascript">
function callid(id)
$(document).ready(function()
{
$("#"+id+"").autocomplete(
{
source:'autocomplete.php',
minLength:1
});
});
</script>
答案 0 :(得分:1)
试试这个:
<div class="my-form">
<p class="text-box">
<input type="text" class="form-control" name="boxes[]" id="Name" value="" placeholder="Name" />
<input type="text" class="form-control" name="boxes[]" value="" id="box1" placeholder="Stripes" />
<a class="add-box" href="#">Add More</a>
</p>
</div>
<script type="text/javascript">
$(document).ready(function()
{
$('input[name="boxes[]"]').autocomplete(
{
source:'autocomplete.php',
minLength:1
});
});
</script>
注意:如果您已动态添加输入框,则需要为每个新添加的项目调用autcomplete