用js获取到的dom伪数组无法执行for循环便利数组,需要将伪数组转为真数组,方法如下:
var liList = document.querySelectorAll('li')
let newList = Array.from(liList)
newList.forEach((item,index,array)=>{
console.log(item,index);
用js获取到的dom伪数组无法执行for循环便利数组,需要将伪数组转为真数组,方法如下: var liList = document.querySelectorAll('li') // 这里用forEach遍历 需要把伪数组转为真数组 // es5语法 // let newList = Array.prototype.slice.call(liList) // es6语法 le...
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>用foreach()方法把类数组对象转换为数组</title>
//1、先把元素集合类数组转化为数组
var ary = utils.listToArray(oLis);//上几节封装好的listToArray
//2、给数组进行排序:按照每一个li中的内容大小进行排序
ary.sort(function(a,b){
return parseFloa...
将
DOM元素li、函数的arguments转化为
真正的
数组
var lis=document.getElementsByTagName("li");
console.log(lis);
//HTMLCollection(3) [li, li, li]
var fun=function(){
console.log(arguments);
//Arguments [callee: ƒ, Symbol(Symbol.iterator): ƒ]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
//2019-06-11 16:18:15
function getDateFromString(str){
var reg = /^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/;
var s = str.match(reg);
var result="";
if(s){
result = ne...
var oFlag = document.getElementById('flag');
var oDiv = document.getElementById('node');
//鼠标移入事件
oDiv.onmouseover = function() {
oFlag.style.display = 'block';
//鼠标移出事件
oDiv.onmouseout = function(...