Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.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
Javascript 如何对先前从jquery追加的div中的元素使用jqueryonclick函数_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 如何对先前从jquery追加的div中的元素使用jqueryonclick函数

Javascript 如何对先前从jquery追加的div中的元素使用jqueryonclick函数,javascript,jquery,ajax,Javascript,Jquery,Ajax,我用class在div中附加了一些元素。display\u noti如下:- $(document).ready(function(){ setTimeout(done,200); }); function done() { setTimeout(updates, 200); // Call updates in 200ms } function updates(){ $.getJSON("notification.php",function(data){ // you c

我用class
在div中附加了一些元素。display\u noti
如下:-

$(document).ready(function(){
setTimeout(done,200);
});

function done() {
setTimeout(updates, 200); // Call updates in 200ms
}

function updates(){

  $.getJSON("notification.php",function(data){  
    // you can do checking here
    if ( data.result && data.result.length > 0 ) {
       $(".display_noti").empty(); // Clear out the div  
       $.each(data.result,function(){  
         $(".display_noti").append("<div class='palnotific'>You got a pal request from <strong>"+this['from_user']+"</strong><br><span class='date'>"+this['notification_date']+"<form method='post'><input type='hidden' value='"+this['pals_id']+"'></form></div>");
       }); 
       done();
    }
    else {
          $(".display_noti").append("<div class='palnotific' style='background-color:white;'>You have no notification to view.</div>");
    }
  });
}
$(文档).ready(函数(){
设置超时(完成,200);
});
函数完成(){
setTimeout(更新,200);//在200ms内调用更新
}
函数更新(){
$.getJSON(“notification.php”,函数(数据){
//你可以在这里检查
if(data.result&&data.result.length>0){
$(“.display_noti”).empty();//清除div
$.each(data.result,function(){
$(“.display\u noti”).append(“您收到了来自的pal请求”+此['from\u user']+”
“+此['notification\u date']+”); }); 完成(); } 否则{ $(“.display_noti”).append(“您没有要查看的通知”); } }); }
我已经从
数据库
中获取了
数据,并将其转换为
json encode
格式,然后我使用上面的jquery函数来获取、验证和添加
div
中的信息。display\u noti

正如你们所看到的,我做这些都是为了我的通知系统所以,每次此代码检查我的数据库中是否有可用的新更新。如果数据库中有一些更改,则在该
中的
200毫秒
元素中。display_noti
div表示类为
的div。palnotific
将自动更新,而无需重新加载/刷新任何页面

现在我的问题是,每
200毫秒
那些
附加的
div就会消失,然后再次出现。如果在我的
.display\u noti
上添加任何新的更新,这是很好的。但是如果我想添加一些jquery
事件处理程序
函数,比如
onclick
,这可能不是很好。我的意思是我想添加一些
onclick
函数在附加的
div
上。我想把
表单
输入值通过
ajax
发送到某个
php
文件,然后对数据库进行一些更改。在这种情况下,正确的方法是什么?伙计们需要帮助


(在页面中,东西不会消失。我刚才说的是源代码,每
200毫秒
东西就会出现,消失会重复)

你的数据库中的pals\u id是自动递增的吗?为什么@VigneswaranS bro?我会给出一个想法。试一试。如果你的pals\u id是自动递增的,那么我们可以得到最大的值。它被追加到你的div中。将该值作为变量(var pal)在下一次更新VAR的检查中,BRO?BRO,我怎么可以使用jQuery <代码> OnCase< /Cord>事件?我希望在用户点击任何附加DIV之后从jQuery中捕获该值,然后在Ajax上使用它来在PHP文件上发送一些更新服务器的方法。添加更多关于您的代码的功能以及它解决问题的原因的解释。一个只包含代码的答案(即使它在工作)通常不会帮助OP理解他们的问题。
$('document').on('click','.palnotific',function(){
    input_val = $(this).find(':input').val();

    //continue ajax here
});