小编Arn*_*rno的帖子

我如何解决这个"无法读取属性'appendChild'的null"错误?

我尝试使用下面的代码,在我的网站上添加幻灯片中的按钮:

window.onload = function loadContIcons() {
    var elem = document.createElement("img");
    elem.src = "http://arno.agnian.com/sites/all/themes/agnian/images/up.png";
    elem.setAttribute("class", "up_icon");

    var id = "views_slideshow_controls_text_next_slideshow-block";
    if (id !== 0) {
        document.getElementById(id).appendChild(elem);
    } else console.log("aaaaa");

    var elem1 = document.createElement("img");
    elem1.src = "http://arno.agnian.com/sites/all/themes/agnian/images/down.png";
    elem1.setAttribute("class", "down_icon");

    var id1 = "views_slideshow_controls_text_previous_slideshow-block";
    if (id1 !== 0) {
        document.getElementById(id1).appendChild(elem1);
    } else console.log("aaaaa");
}
Run Code Online (Sandbox Code Playgroud)

在首页上,我有幻灯片显示一切正常,但在其他页面上Cannot read property 'appendChild' of null发生错误.

javascript jquery drupal

16
推荐指数
2
解决办法
9万
查看次数

标签 统计

drupal ×1

javascript ×1

jquery ×1