我正在尝试插入 h2 标记,并使其成为垂直导航菜单中所有链接的父级。
我可以为单个元素执行此操作,但现在我想对菜单中的所有元素执行此操作。
JavaScript的:
var menu_item = document.querySelector("div.righ-nav-style1 ul li a");
// `menu_item` is the element you want to wrap
var parent = menu_item.parentNode;
var wrapper = document.createElement('h2');
wrapper.className = 'category_links';
// set the wrapper as child (instead of the 'menu_item')
parent.replaceChild(wrapper, menu_item);
// set 'menu_item' as child of wrapper
wrapper.appendChild(menu_item);
我想在forloop中为所有菜单项使用 replaceChild()和 appendChild()方法。
非常感谢任何帮助!
答案 0 :(得分:0)
编辑JavaScript:
var date = new Date('2017-03-16T14:11:48.700000')
date.getMonth()+1 // 3
date.getDate() // 16
date.getFullYear() // 2017
...