您好我有一些输入,我使用自动完成但我有一个添加行但是当我添加行时,我没有选择自动完成功能。我如何在新行上自动完成?
我在这里如何进行自动填充:
//------------------AUTO COMPLETE NUMÉRO DE PROJET----------------------
$(document).ready(function(){
//-------AUTO COMPLETE DIMANCHE PROJET-----
$("#projdim").autocomplete({
source:'getautocomplete.php',
minLength:1
如果按下
//------------------COMPLETE CLIENT DESC DIMANCHE----------------------
function handleEnter(e, obj, field){
if (e.keyCode == 13 || e.which == 13){
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
tempArrayInJS = JSON.parse(xmlhttp.responseText);
$("#clientdim").val( tempArrayInJS[0]['cliName']);
$("#prodescdim").val( tempArrayInJS[0]['proDescription']);
}
}
xmlhttp.open("GET","completeclient.php?q="+obj.value,true);
xmlhttp.send();
}
//Enter was pressed, handle it here
}
这是我输入的原始
<span id="numpro" >
<input onblur="autre();" onfocus="enter();" type="text" id="projdim" name="projdim"onkeypress="return handleEnter(event, this, 'task');"/>
</span>
这是我如何添加行
<?php if (!isset($_POST['Terminé'])) { ?>
<form action="insert.php" method="post" >
<b>Dimanche</b> </br><?php echo $date1 ?>
<p id="add_field"><a href="#"><span>add</span> </a></p>
</td>
My JS of adding row
<script type="text/javascript">
var counter = 0;
$(function(){
$('p#add_field').click(function(){
counter += 1;
$('#numpro').append(
'<input id="field_' + counter + '" name="dynfields[]' + '" type="text" />'
);
$('#proclient').append(
'<input id="field_' + counter + '" name="dynfieldstest[]' + '" type="text" /><br />'
);
});
});
</script>
答案 0 :(得分:0)
目前,您只是向身份projdim
的元素添加自动填充功能。您需要对要使其生效的每个元素运行自动完成功能。例如,将附加功能更改为
$('p#add_field').click(function(){
counter += 1;
var $newRow = $('<input id="field_' + counter + '" name="dynfields[]' + '" type="text" />');
$('#numpro').append($newRow);
$newRow.autocomplete(autocompOpt);
...
autocompOpt
这是一个表示自动填充选项的对象。在您提供的代码中,类似
var autocompOpt = {
source:'getautocomplete.php',
minLength:1
}