ajax 动态加载的内容,相应的js也要在回调里加载,不然之前已经写好的监听函数,其实没有绑定到后来动态加载的元素上的,所以要写成回调的形式比如:
$(".getStudent").click(function(event){
console.log($(this));
var account = $(this).attr("target")
$.ajax({
url: ‘/getStudent‘,
type: ‘POST‘,
dataType: ‘html‘,
data: {studentAccount:account},
})
.done(function(data) {
console.log(data);
$("#replacable").replaceWith(data);
$(".getHomeworkState").click(function(event){
console.log($(this));
var id = $(this).attr("target");
var title = $(this).text();
var student = {{.Account}}
$.ajax({
url: ‘/getHomeworkState‘,
type: ‘POST‘,
data: {
homeworkId:id,
title:title,
account:student
},
})
.done(function(data) {
console.log(data);
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
});
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
});
ajax 动态加载的内容,相应的js也要在回调里加载,布布扣,bubuko.com
原文:http://www.cnblogs.com/ggaaooppeennngg/p/3594883.html