jquery selectがajax成功関数の外部にある場合、ajax呼び出しを介して挿入された要素を選択できません。私が成功の下ですべてを動かすならば、それはうまく働きます。
経験のある人は、何が起こっているのか、そしてこの問題にどのように対処するのかを理解するのを手伝ってくれませんか?私は2日間検索していますが、すでに何も見つかりません:S
これは機能します:
//Show levels using ajax
//define variables
var levels = 2; //level count can be rewritten to come from DB and not be hardcoded like now
var completed_calls = 0; //count tasks start from 0
var views = new Array();
//All level display ajax function
function create_views(level) {
$.ajax({
url: "actions.php",
type: "GET",
data: "show_level=" + level,
cache: false,
success: function (data){
views[level] = '<li data-level="' + level + '">' + data + '</li>';
//Count completed tasks
completed_calls++;
//if last level is being called append and activate slider
if (levels == completed_calls) {
//append views to container
$(".slides_container").append(views.join(' '));
//activate slider
var unislider = $(".slides_container").dpUniSlider({
//loop: false,
draggable: false
});
//Login and Registration windows on login slide, one closes the other opens up
//+ login registration links in header for logged out users
//Login
$("#header-login, #logwindow").on("click", function(){
$("#regsitrationform").hide();
$("#register h2").hide();
$("#loginform").show().css("opacity",0);
unislider.goToSlide(2);
$("#loginform, #register h2").delay(480).fadeTo(0, 1);
$("#logwindow").removeClass("active").addClass("notactive");
$("#regwindow").removeClass("notactive").addClass("active");
return false;
});
//Registration
$("#header-register, #regwindow").on("click", function(){
$("#loginform").hide();
$("#register h2").hide();
$("#regsitrationform").show().css("opacity",0);
unislider.goToSlide(2);
$("#regsitrationform, #register h2").delay(480).fadeTo(0, 1);
$("#regwindow").removeClass("active").addClass("notactive");
$("#logwindow").removeClass("notactive").addClass("active");
return false;
});
//Pop-up logo tooltip: close
$(".close").on("click", function(){
$(".logo").fadeTo("slow", 1);
$(this).parent().fadeOut("fast");
return false;
});
//Pop-up logo tooltip: clear
$(".clear").on("click", function(){
$(this).parent().find("input").val("");
return false;
});
//Activate Georgian keyboard for some logos
$("input[data-lang=ge]").GeoKBD();
}
}
});
}
//Loop through all levels and display views
for (var i=1; i<=levels; i++) {create_views(i);}
これはしません:
//Show levels using ajax
//define variables
var levels = 2; //level count can be rewritten to come from DB and not be hardcoded like now
var completed_calls = 0; //count tasks start from 0
var views = new Array();
//All level display ajax function
function create_views(level) {
$.ajax({
url: "actions.php",
type: "GET",
data: "show_level=" + level,
cache: false,
success: function (data){
views[level] = '<li data-level="' + level + '">' + data + '</li>';
//Count completed tasks
completed_calls++;
//if last level is being called append and activate slider
if (levels == completed_calls) {
//append views to container
$(".slides_container").append(views.join(' '));
//activate slider
var unislider = $(".slides_container").dpUniSlider({
//loop: false,
draggable: false
});
}
}
});
}
//Loop through all levels and display views
for (var i=1; i<=levels; i++) {create_views(i);}
//Ajax call to display-update single level
function update_view(level) {
}
//Login and Registration windows on login slide, one closes the other opens up
//+ login registration links in header for logged out users
//Login
$("#header-login, #logwindow").on("click", function(){
$("#regsitrationform").hide();
$("#register h2").hide();
$("#loginform").show().css("opacity",0);
unislider.goToSlide(2);
$("#loginform, #register h2").delay(480).fadeTo(0, 1);
$("#logwindow").removeClass("active").addClass("notactive");
$("#regwindow").removeClass("notactive").addClass("active");
return false;
});
//Registration
$("#header-register, #regwindow").on("click", function(){
$("#loginform").hide();
$("#register h2").hide();
$("#regsitrationform").show().css("opacity",0);
unislider.goToSlide(2);
$("#regsitrationform, #register h2").delay(480).fadeTo(0, 1);
$("#regwindow").removeClass("active").addClass("notactive");
$("#logwindow").removeClass("notactive").addClass("active");
return false;
});
//Pop-up logo tooltip: close
$(".close").on("click", function(){
$(".logo").fadeTo("slow", 1);
$(this).parent().fadeOut("fast");
return false;
});
//Pop-up logo tooltip: clear
$(".clear").on("click", function(){
$(this).parent().find("input").val("");
return false;
});
//Activate Georgian keyboard for some logos
$("input[data-lang=ge]").GeoKBD();