Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多个textarea在php中使用相同的jquery代码_Jquery - Fatal编程技术网

多个textarea在php中使用相同的jquery代码

多个textarea在php中使用相同的jquery代码,jquery,Jquery,我有一个代码,其中有多个文本区域需要自动保存到数据库中的数据更新时,我使用类而不是id,但它似乎不工作,我不知道哪部分是错误的。有人能帮忙吗 代码如下: <?php foreach($queryRecords as $res) :?> <td width="160"> <div class="form-group"> <textarea name="date[]" id="" rows="1" c

我有一个代码,其中有多个文本区域需要自动保存到数据库中的数据更新时,我使用类而不是id,但它似乎不工作,我不知道哪部分是错误的。有人能帮忙吗

代码如下:

<?php foreach($queryRecords as $res) :?>
<td width="160">
            <div class="form-group">
                 <textarea name="date[]" id="" rows="1" class="form-control date"><?php echo $res['date'];?></textarea>  
            </div></td>
<td width="160">
            <div class="form-group"> 
                 <textarea name="action[]" id="" rows="1" class="form-control action"><?php echo $res['action'];?></textarea>  
            </div></td>

<div class="form-group">  
            <input type="hidden" name="id[]" id="" class="form-control id" value="<?php echo $res['id'];?>" />
                 <div class="autoSave_quo"></div>
            </div>  
        </td>
</tr>
<?php endforeach;?>
<script>  
$(document).ready(function(){
var timer_quo;
var timeout_quo = 1000;
$('.date, .action').change(function(){

if(timer_quo) {
clearTimeout(timer_quo);
}
timer_quo = setTimeout(autoSave_quo, timeout_quo); 

});
});

function autoSave_quo(){
    var date = $(this).parent().find('.date').val();
    var action = $(this).parent().find('.action').val();
    var gp_name = $(this).parent().find('.gp_name').val();
    var id = $(this).parent().find('.id').val();
   if(date != '' && gp_name != '')  
   {  
        $.ajax({  
             url:"lotus_cover_ref.php",  
             method:"POST",  
                 data:{date:date, action:action, gp_name:gp_name, id:id},  
             dataType:"text",  
             success:function(data)  
            {  
                  if(data != '')  
                  {  
                       $('.gp_name').val(data);
                       $('.id').val(data);
                  }  
                  $('.autoSave_quo').text(location.reload());  
            }  
    });  
} 
}   
</script>


在您的
函数autoSave_quo
中,您使用的是
$(此)
,但您的代码无法找到进行更改的当前元素,只需将
$(此)
放入某个变量中,然后将其添加到函数参数中。即:使用虚拟数据:

$(文档).ready(函数(){
变量计时器;
var超时=1000;
$('.date,.action').change(函数(){
如果(计时器){
清除超时(计时器);
}
//将电流元件置于可变电流中
当前变量=$(此)
//将其作为参数在函数中传递
timer_quo=设置超时(自动保存(当前),超时);
});
});
自动保存功能(当前){
//使用当前->div->td->tr->日期查找所选值
var date=current.parent().parent().parent().find('.date').val();
控制台日志(日期);
var action=current.parent().parent().parent().find('.action').val();
控制台日志(操作);
var gp_name=current.parent().parent().parent().find('.gp_name').val();
var id=current.parent().parent().parent().find('.id').val();
console.log(id);
如果(日期!=''&&gp_名称!=''){
$.ajax({
url:“lotus\u cover\u ref.php”,
方法:“张贴”,
数据:{
日期:日期:,
行动:行动,
gp_名称:gp_名称,
id:id
},
数据类型:“文本”,
成功:功能(数据){
如果(数据!=''){
$('.gp_name').val(数据);
$('.id').val(数据);
}
$('.autoSave_quo').text(location.reload());
}
});
}
}


在您的
函数autoSave_quo
中,您使用的是
$(此)
,但您的代码无法找到进行更改的当前元素,只需将
$(此)
放入某个变量中,然后将其添加到函数参数中。即:使用虚拟数据:

$(文档).ready(函数(){
变量计时器;
var超时=1000;
$('.date,.action').change(函数(){
如果(计时器){
清除超时(计时器);
}
//将电流元件置于可变电流中
当前变量=$(此)
//将其作为参数在函数中传递
timer_quo=设置超时(自动保存(当前),超时);
});
});
自动保存功能(当前){
//使用当前->div->td->tr->日期查找所选值
var date=current.parent().parent().parent().find('.date').val();
控制台日志(日期);
var action=current.parent().parent().parent().find('.action').val();
控制台日志(操作);
var gp_name=current.parent().parent().parent().find('.gp_name').val();
var id=current.parent().parent().parent().find('.id').val();
console.log(id);
如果(日期!=''&&gp_名称!=''){
$.ajax({
url:“lotus\u cover\u ref.php”,
方法:“张贴”,
数据:{
日期:日期:,
行动:行动,
gp_名称:gp_名称,
id:id
},
数据类型:“文本”,
成功:功能(数据){
如果(数据!=''){
$('.gp_name').val(数据);
$('.id').val(数据);
}
$('.autoSave_quo').text(location.reload());
}
});
}
}


为什么要在每个jquery语句中添加.parent()。尝试删除它为什么要在每个jquery语句中添加.parent()。试着把它去掉谢谢,它能用!!这对我来说有点复杂,需要一些时间来理解。谢谢,它很有效!!这对我来说有点复杂,需要一些时间来理解。