我对 jQuery 可拖动 UI 有一个非常简单的问题。我输入了一个函数,它的名字是 inid_drag,当我在 ajax 之后调用它的工作良好。但是在ajax调用之前输入时它不起作用。
遵循可拖动代码:
function init_drag(){
$("#lessonTeacher li").draggable({
helper: 'clone'
});
}
以下代码工作正常:
$("#classID").change(function(){
var classID = $(this).val();
$.ajax({
async: false,
type: "POST",
dataType: "json",
data:"classID=" + classID,
url: "views/timeTablesAjax.php",
success:function(data){
$("#lessonTeacher").html("");
$("#timeTable").hide();
$("#timeTable").show("slow");
$("#timeTable td").not(".notDrop").html("");
$.each(data,function(i,persons){
$("#lessonTeacher").append("<b>" + persons[0].code + "</b><br/>");
for(var i = 0; i < persons.length; i++){
$("#lessonTeacher").append("<li class='token-input-token-facebook' style='list-style-type: none;'>" +
"<p style='padding-left: 10%;' data-id=" + persons[i].ID + ">" + persons[i].staff + "</p>" +
"<span class='infoBox' style='background-color: #808080;'><img src='BT/upload/info.ico' width=10 height=10></span></li><br/><br/>");
}
});
// in this function has got draggable codes.
init_drag();
}
});
});
跟随代码不起作用:
$("#classID").change(function(){
var classID = $(this).val();
// in this function has got draggable codes.
init_drag();
$.ajax({
async: false,
type: "POST",
dataType: "json",
data:"classID=" + classID,
url: "views/timeTablesAjax.php",
success:function(data){
$("#lessonTeacher").html("");
$("#timeTable").hide();
$("#timeTable").show("slow");
$("#timeTable td").not(".notDrop").html("");
$.each(data,function(i,persons){
$("#lessonTeacher").append("<b>" + persons[0].code + "</b><br/>");
for(var i = 0; i < persons.length; i++){
$("#lessonTeacher").append("<li class='token-input-token-facebook' style='list-style-type: none;'>" +
"<p style='padding-left: 10%;' data-id=" + persons[i].ID + ">" + persons[i].staff + "</p>" +
"<span class='infoBox' style='background-color: #808080;'><img src='BT/upload/info.ico' width=10 height=10></span></li><br/><br/>");
}
});
}
});
});