Error: Uncaught TypeError: Cannot read property 'value' of null

前端 未结 5 1134
忘了有多久
忘了有多久 2021-01-29 15:05

i want to know why this error is occuring \"Uncaught TypeError: Cannot read property \'value\' of null\" and where i am going wrong?

 function create()
                 


        
5条回答
  •  北海茫月
    2021-01-29 15:21

    I'll try to tackle some of the problems with your code (in hope that they magically match your HTML):

    function create(){
        var textbox = document.createElement("input");
        var para = document.createElement("p");
        para.setAttribute("id", "p");
        textbox.type = 'text';
        textbox.value='asdf';
        textbox.setAttribute("id","textbox");
        // The following is a valid way to attach an event handler:
        textbox.onblur = function(){ 
            para.innerHTML = document.getElementById('textbox').value);
        }
        document.body.appendChild(textbox);
    }
    

提交回复
热议问题