HTMLCollection集合能打印出来值,但是无法获取每一个值。

var imgs = $("#pictureQueryTable img").prevObject[0].images;

下图是上面这句打印出来的结果:
clipboard.png

console.log可以打印出来该集合的数据,但是无法获取该集合中的每一个值,打印该集合的length为0,所以也无法遍历该集合进行操作。查资料看有人说要在dom结构完全加载完成之后才能操作,但是试了之后发现还是不行。

下面这个图是console.log($("#pictureQueryTable img"))打印出来的数据

clipboard.png

clipboard.png

代码结构是这样的:

clipboard.png

图片生成代码是这样的:

clipboard.png

{
            title : "",
            name : "PICTURE_NAME1",
            width : 320,
            lockWidth : false,
            align : "center",
            renderer : function(val, item, rowIndex) {
                if (item.COLLECTION_NAME1 != undefined) {
                    picture_path = "image/no_picture.png";
                    var picture_name = item.COLLECTION_NAME1 + "("
                        + item.COLLECTION_CODE1 + ")";
                    if (item.PICTURE_PATH1) {
                        picture_path = getLocaleHostPath()
                            + item.PICTURE_PATH1;
                    }
                    val = val != null ? val : "";
                    return "<div style='width:310px;height:100%;text-align:center;background-color:white;padding-top:5px;'><div>"
                        + "<a href='javascript:void(0)' onclick='openPage(\"html/showcenter/collection/collectionstatistical/picturequery/PictureDetailInfo.html?id="
                        + item.COLLECTION_ID1
                        + "&collection_code="
                        + item.COLLECTION_CODE1
                        + "\",\"1300,600\")'>"
                        + "<img alt='图片' style='width:200px;height:200px;' title='"+val+"' src='"+picture_path
                        +"'/></a></div><span style='margin-top:5px;'>"
                        + picture_name + "</span></div>";
                } else {
                    return "";
                }
            }
        }
阅读 8.8k
1 个回答
查资料看有人说要在dom结构完全加载完成之后才能操作,但是试了之后发现还是不行。

就是这原因,看到那个感叹号了么,点开一下。你打印的时候里面还没值,你打印的是引用,查看的时候生成快照才有值。要么断点要么JSON.stringify()转一下。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题