欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Cannot read property ‘getAttribute‘ of null

程序员文章站 2022-06-07 13:18:28
...
        function popUp(winURL){
            window.open(winURL,"popup","width=320,height=480");
        }
        
        window.onload = prepareLinks;
        function prepareLinks(){
            var a = document.getElementById("a");
            if(a.getAttribute("class") == "popup"){
                a.onclick = function(){
                    popUp(this.getAttribute("href"));
                    return false;
                }
            }
        }
    <a href="https://cn.bing.com/" class="popup" >Example</a>