今天在复习dom节点的创建的时候发现打印日志的时候,不管log的位置在哪里,打印出的节点始终是最新的
这就让我很困惑了,js不是由上到下执行的吗,然后问了同事,他分享了打印对象时候的类似的现象
先展示下打印dom节点的demo
/*创建标签节点*/
var p_tag = document.createElement('p');
console.log('p_tag: ', p_tag);/*创建文本节点*/
var text_node = document.createTextNode('我是文本节点');
console.log('text_node: ', text_node);/*创建标签节点*/
var style_attribute = document.createAttribute('style');
style_attribute.value= "color: red;"console.log('style_attribute: ', style_attribute);/*组合标签节点,文本节点,标签节点*/p_tag.appendChild(text_node);
p_tag.setAttributeNode(style_attribute);
console.log('p_tag complex: ', p_tag);
console.log('p_tag complex text: ', p_tag.innerHTML);///* 给标签设置内容 */
p_tag.innerHTML = "我是p的文案"console.log('p_tag t