Javascript 如何循环通过AJAX加载的复选框?

Javascript 如何循环通过AJAX加载的复选框?,javascript,jquery,Javascript,Jquery,我想在通过AJAX加载的复选框上执行以下操作: $('input:checkbox').each(function() { $(this).hide(); alert("hi"); $('<div class="checkbox-fx"><div class="checkbox"></div></div>').insertAfter(this); }); $('input:checkbox'

我想在通过AJAX加载的复选框上执行以下操作:

$('input:checkbox').each(function() {
        $(this).hide();
        alert("hi");
        $('<div class="checkbox-fx"><div class="checkbox"></div></div>').insertAfter(this);
    });
$('input:checkbox')。每个(函数(){
$(this.hide();
警报(“hi”);
$('')。在(本)之后插入;
});
文档加载时,复选框尚未加载,因此该函数未实现。如何循环新加载的复选框


谢谢

假设使用类似于
$.ajax
的方法加载复选框,则
成功
方法将在将结果HTML添加到文档后处理它

$.ajax({
 // your ajax options here
 success: function(html) {
    $(html).find('input:checkbox').each(function() {
        $(this).hide();
        alert("hi");
        $('<div class="checkbox-fx"><div class="checkbox"></div></div>').insertAfter(this);
    }).appendTo(document.body); // takes the HTML from the ajax call and processes each checkbox. when done, the results are then appended to the document
 }
});
$.ajax({
//这里有您的ajax选项
成功:函数(html){
$(html).find('input:checkbox').each(function(){
$(this.hide();
警报(“hi”);
$('')。在(本)之后插入;
}).appendTo(document.body);//从ajax调用中获取HTML并处理每个复选框。完成后,结果将追加到文档中
}
});

假设复选框是使用类似于
$.ajax
的东西加载的,那么您的
成功
方法就是在将结果HTML添加到文档后处理它

$.ajax({
 // your ajax options here
 success: function(html) {
    $(html).find('input:checkbox').each(function() {
        $(this).hide();
        alert("hi");
        $('<div class="checkbox-fx"><div class="checkbox"></div></div>').insertAfter(this);
    }).appendTo(document.body); // takes the HTML from the ajax call and processes each checkbox. when done, the results are then appended to the document
 }
});
$.ajax({
//这里有您的ajax选项
成功:函数(html){
$(html).find('input:checkbox').each(function(){
$(this.hide();
警报(“hi”);
$('')。在(本)之后插入;
}).appendTo(document.body);//从ajax调用中获取HTML并处理每个复选框。完成后,结果将追加到文档中
}
});
$.ajax({
url:'/YourUrl',类型:'Get',数据类型:'json',
//数据:{id:'},
成功:函数(html){
$(html).find('input:checkbox').each(function(){
if($(this).next('div.checkbox-fx')。长度==0)
{
$(this.hide();
$('')。在(本)之后插入;
}
}).附录(文件正文);
}
});
$.ajax({
url:'/YourUrl',类型:'Get',数据类型:'json',
//数据:{id:'},
成功:函数(html){
$(html).find('input:checkbox').each(function(){
if($(this).next('div.checkbox-fx')。长度==0)
{
$(this.hide();
$('')。在(本)之后插入;
}
}).附录(文件正文);
}
});

请张贴您用来加载它们的方法,以便我们能够以适当的焦点来处理此问题。或者,澄清您发布的代码是唯一的方法-鉴于此,您可能需要显示第一个代码的标记。请发布您用于加载它们的方法,以便我们能够以适当的焦点处理此问题。或者,澄清您发布的代码是唯一的方法——鉴于此,您可能需要显示第一个方法的标记。