js加载出来的checkbox,用$("input:checkbox")无法找到

js加载出来的checkbox,用$("input:checkbox")无法找到,就解决办法

直接$(":checkbox")试试了

你是先执行的$("input:checkbox") ,后面再生成的dom 标签 ,所以找不到这个 ,需要等js动态加载完dom结构 ,再选
//你生成 dom的代码
$(document).ready(function{
$("input:checkbox")
})

把你代码贴出来看看呗

$(function () {
    $("#vjxj .li").remove();
    _p = 1;//设置起始页码
    getJxjlist();
    //sleep(600);
    ckdClick();
});
function sleep(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}
function getJxjlist() {
    var tp = $("#vjxj .li");
    var len = tp.length - 1;
    $.post("/wx/GetWxJxj", { page: _p },
       function (d, t, j) {
           if (t == "success") {
               $(tp.eq(len)).remove();
               var datarows = d.rows.length;
               var tps = "";
               for (i = 0 ; i < datarows; i++) {
                   tps = "<div class=\"li\" style=\"width: 100%;\">"

                        + "<div class=\"bf fl\">"
                            + "<div>"
                            + '<img class="" style="width:317px;height:130px;" alt="" src="/Images/icon/jxj.png">'
                            + '<div class="sp" style="position: absolute;margin-top: 30px;\
                           margin-left:45px;\
                           width: 190px;\
                           height: 20px;\
                           font-size: 12px;">\
                    <p><span style="font:400 30px Simsun;color:white;font-weight:bold;">'+ d.rows[i].CouponMoney + '</span></p>\
                </div>'
                            + '<div class="sp" style="position: absolute;\
                           margin-top: 45px;\
                           margin-left: 105px;\
                           width: 190px;\
                           height: 20px;\
                           font-size: 22px; text-align:center">\
                    <p><span style="font:400 10px Simsun;color:#6d9cdc;font-size: 16px;font-weight:bold;">'+ d.rows[i].CouponName + '</span></p>\
                </div>'
                            + '<div class="sp" style="position: absolute;\
                           margin-top: 100px;\
                           margin-left: 90px;\
                           width: 220px;\
                           height: 20px;\
                           font-size: 12px; text-align:right">\
                    <p><span style="font:400 10px Simsun;color:#a6b0b0">有效期至 '+ d.rows[i].endtime + '</span></p>\
                </div>'
                            + '<div class="sp" style="position: absolute;\
                           margin-top: 55px;\
                           margin-left: 320px;\
                           width: 220px;\
                           height: 20px;\
                           font-size: 12px; text-align:left">\
                           <input value="' + d.rows[i].LimitMoney + '" class="ckbJxj" type="checkbox"/>\
                           <label style="color:red;font-size:13px;"></label>\
                           <input  type="text" value="' + d.rows[i].ID + '" style="display:none" />\
                           <input type="text" value="' + d.rows[i].CouponMoney + '" style="display:none" />\
                </div>'
                            + "</div>"
                             + "<div class=\"clearfix\"></div>"
                        + "</div>"
                       + "<hr style=\"width:100%; height:4px; background:#f5f5f5; border:none; \">"
                       + "</div>";
                   $("#vjxj").append(tps);
               }
               if (_p * 10 < d.total) {
                   var gd = "<div class=\"li\" style=\"height: 40px;display: flex;\"><a style=\"margin:0 auto;color:#666;font-size:2.3rem;\" href=\"javascript:getJxjlist()\">查看更多<img style=\"margin-left: 10px;width: 18px;height: 11px;\" src=\"/images/icon/arrow2.png\"></a></div>";
                   $("#vjxj").append(gd);
               }
               _p++;
           }
       }, "json");
}
function ckdClick() {

    //$('#vjxj').find(':checkbox').each(function () {
    //    alert($("input:checkbox").length);
    //});
    alert($('input:checkbox').length);
    $('input:checkbox').each(function () {
        alert(1);
    });
            }

getJxjlist();这个方法是创建,ckdClick() 这个是设置创建元素的事件。看顺序没错,但是getJxjlist创建用的ajax异步的,所以会先执行了ckdClick() 方法,所以找不到。将方法ckdClick() 放到 getJxjlist()方法里面你的循环完成之后。

var isCMISChecked = $("#F_CMIS").is(":checked");我的这个是单个的CheckBox检查是否选中

ajax异步的,都没返回都已经执行ckdClick了,当然获取不到checkbox,ajax改为同步或者ckdClick放到getJxjlist()的ajax回掉中执行,由于你用$.post,是异步的无法配置同步(同步需要$.ajax),只能回掉里面执行ckdClick

 function getJxjlist() {
    var tp = $("#vjxj .li");
    var len = tp.length - 1;
    $.post("/wx/GetWxJxj", { page: _p },
       function (d, t, j) {
           if (t == "success") {
                //............原来的代码

                ckdClick() ////////////////
                     }
}, "json");

同上,你只要将每次异步加载的js里重新加载相关函数,就能取到对应的值,先下蛋,后生鸡。没蛋孵不出鸡