Discuss / JavaScript / biubiu

biubiu

Topic source

w_玉芳

#1 Created at ... [Delete] [Delete and Lock User]

var parent = document.querySelector('#test-list'); //拿到父节点 var childList = parent.children; //拿到所有子元素 var ans = ['JavaScript','HTML','CSS']; //给出一个匹配数组 for(let i = 0; i < childList.length; i++){ //检索数组,如果数组中不存在第i个字符串值。 if(ans.indexOf(childList[i].innerText) === -1){
//移出该不符合答案的字符串 parent.removeChild(childList[i]);
} }


  • 1

Reply