当我的ajax请求完成时,我的功能无效。
这是我的剧本:
<script>
function sendmsg(id,msg){
alert('id is'+id+'and msg is '+msg);
}
<script>
<div class="div1">
<div id="ajaxreq">
</div>
<input type="button" onclick="loadmore();" />
</div>
<script>
function loadmore(){
$.ajax({
URL:"div1.php",
data:"act=get",
type:"GET",
success: function(data){
if(data !=""){
$("#ajaxreq").append(data);
}
},
error: function(data){
alert("Error Load");
}
});
}
</script>
添加数据时:
<div id="ajaxreq">
<div id="content">
<img src="./img/1.png">
<input type="button" onclick="sendmsg("1","Image1");"/> // this is what is want to do//
</div>
</div>
答案 0 :(得分:0)
如果您未使用javascript或jquery在event
上使用button
绑定,请修复您的button
代码段,
<input type="button" onclick="sendmsg("1","Image1");"/>
要,
<input type="button" onclick="sendmsg('1','Image1');"/>
编辑:
在你的成功ajax处理程序中,
success: function(data){
if(data !=""){
$("#ajaxreq").append(data);
$("#ajaxreq").on('click','button', function(){
//add your button click logic
});
//trigger click on this button
//your button dont have any id so do like this..
$("#ajaxreq").find("button").click();
}
},