我正在尝试创建一个添加行的函数,但我在keypress
上的函数不起作用/。我尝试使用"
,'
,没有它就没有区别。当我按下按钮时没有发生任何事情。
//function append lundi
var counterlundi= 0;
var $newRow ;
$(function(){
$('#add_lundi').click(function(){
counterlundi += 1;
$('#numlundi').append($newRow = $('<input id="numlundi' + counterlundi + '" name="numlundi[]' + '" type="text" onblur="autre();" onfocus="enter();"/> '
)
)
我该怎么做?
这是我的自动完成静态输入的php
<td>
<b>Lundi</b> </br><?php echo $date2 ?>
<div id="lundicon">
<p id="add_lundi" class="plus"><a href="#"><span> + </span> </a></p>
</div>
</td>
<td>
<div id="numlundi">
<input onblur="autre();" onfocus="enter();" size="10" type="text" id="projlundi" name="projlundi"onkeypress="return handleEnter2(event, this, 'task');"/>
</div>
</td>
<td>
<div id="clientlun">
<input type="text" name="clientlundi" onblur="autre();" onfocus="enter();" class = "client" size="12" id ="clientlundi" readonly />
</div>
</td>
<td>
<div id="prodesclun">
<input type="text" name="projdesclundi" onblur="autre();" onfocus="enter();" size="30" class "desc" id ="projdesclundi"readonly />
</div>
</td>
我的静态输入的Javascript功能
//-------AUTO COMPLETE LUNDI PROJET-----
$("#projlundi").autocomplete({
source:'getautocomplete.php',
minLength:1
});
function handleEnter2(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);
$("#clientlundi").val( tempArrayInJS[0]['cliName']);
$("#projdesclundi").val( tempArrayInJS[0]['proDescription']);
}
}
xmlhttp.open("GET","completeclient.php?q="+obj.value,true);
xmlhttp.send();
}
}
答案 0 :(得分:0)
$('#numlundi').on('keypress', 'input', function(e){
var $this = $(this);
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);
if ($this.attr('id') != 'numlundi') {
var id = $this.attr('id').replace('numlundi', '');
$("#clientlundi"+id).val( tempArrayInJS[0]['cliName']);
$("#projdesclundi"+id).val( tempArrayInJS[0]['proDescription']);
} else {
$("#clientlundi").val( tempArrayInJS[0]['cliName']);
$("#projdesclundi").val( tempArrayInJS[0]['proDescription']);
}
}
}
xmlhttp.open("GET","completeclient.php?q="+$this.val(),true);
xmlhttp.send();
}
})