简体   繁体   English

将Jquery与post ajax的数据结果的div一起使用

[英]Use Jquery with the div of a data result of a post ajax

I have this post code in a one.jsp 我在one.jsp中有此邮政编码

$.post("<%=request.getContextPath()%>/two.jsp", {
            vaedre: fullDate}
         ,function(result){
           $("#theresult").append(result);
          });

And it generate in one.jsp: 并在one.jsp中生成:

<div id="theresult">
<div id="kily"></div>
</div>

If I try to use this jquery code, that is in one.jsp it doesnt work: 如果我尝试使用此jquery代码,则在one.jsp中不起作用:

$('#kily').click(function() {
alert("this is a test");
});

I think that is beacuse the div kily is in two.jsp but not in one.jsp altought it seems to be in one.jsp after the append. 我认为这是因为div kily在two.jsp中,而不是在one.jsp中,它似乎在追加之后在one.jsp中。

Any help? 有什么帮助吗?

Thanks!! 谢谢!!

Either us . 要么我们。 $(document)on('click', '#kily', function(){}); $(document)on('click','#kily',function(){});

or create your click event after you append the element 或在添加元素后创建click事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM