javascript - Question about inserting html using native js
给我你的怀抱
给我你的怀抱 2017-06-26 10:58:39
0
3
1074

Error message: Uncaught TypeError: Failed to execute 'insertBefore' on 'Node': parameter 1 is not of type 'Node'.

I want to concatenate the string after the corresponding tr when the addChild method is triggered. How should I write addChild?

-----renew

Dear friends who answered, thank you, the problem is solved, I used the method on the first floor

给我你的怀抱
给我你的怀抱

reply all(3)
小葫芦

The first parameter requirement is that the Dom node is not a string

Try insertAdjacentHTML

淡淡烟草味

tpl is a string, not a node object, so an error is reported;
You can use event bubbling to write the addChild method on tr or tbody (depending on whether each tr requires this method),
then use the event object Use the target attribute to find the corresponding tr, and then perform subsequent operations;

淡淡烟草味

The error message is very obvious, tpl is a string, not a node element

https://developer.mozilla.org...

You have to convert the string into dom

For example, a function like this is used to convert a string into DOM. The code is only for reference

var toElement = (function(){
        var p = document.createElement('p');
        return function(html){
            p.innerHTML = html;
            var el = p.firstChild;
            return p.removeChild(el);
        };
    })();
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template