[英]how to use jquery onClick function on element inside a div which were previously appended from jquery
I have appended some element inside a div with class .display_noti
like :- 我已经在类
.display_noti
的div中添加了一些元素,例如:
$(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>");
}
});
}
I have fetched
data from database
and converted it on json encode
format and then I used that above jquery function to get,validate and add those information inside that div
with class .display_noti
. 我有
fetched
由数据database
,并转换它json encode
格式,然后我用上面的jquery函数来获得,验证和添加内部那些信息div
与类.display_noti
。
As you guys can see i'm doing this all for my notification system so, every time this code checks new update available or not in my database.If there's some changes in database then in every 200 milliseconds
element inside that .display_noti
div which mean div with class .palnotific
will automatically get updated without any page reload/refresh. 大家可以看到我正在为通知系统执行所有操作,因此每次此代码检查数据库中是否有新的更新时。如果数据库中有某些更改,则
.display_noti
div中的每200 milliseconds
元素中具有.palnotific
类的div将自动更新,而无需重新加载/刷新任何页面。
Now my problem is that every 200 milliseconds
those appended
div get vanish and then come again.It's good if there was any new update it will add on my .display_noti
but it might be not that good if i want to add some jquery event handler
function like onclick
.I mean i want to add some onclick
function on that appended div
.I want to take that form
input value and send it via ajax
to some php
file for the process and make some changes on database.What will be the proper way to do that in such case?Guys need help. 现在我的问题是,每
200 milliseconds
这些appended
div消失并再次出现。如果有任何新更新它将添加到我的.display_noti
是很好的,但是如果我想添加一些jquery event handler
函数可能就不那么好了像onclick
一样。我的意思是我想在该附加的div
上添加一些onclick
函数。我想采用该form
输入值,并通过ajax
将其发送到该过程的php
文件中,并对数据库进行一些更改。要在这种情况下做到这一点?
(In page things doesn't vanish.I was talking about source code where every 200 milliseconds
things appear and vanish repeats) (在页面中,事情不会消失。我所说的是每
200 milliseconds
出现一次并消失重复的源代码)
$('document').on('click','.palnotific',function(){
input_val = $(this).find(':input').val();
//continue ajax here
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.