How to check if an object is an instance of a NodeList in IE?

后端 未结 4 973
心在旅途
心在旅途 2020-12-31 20:19

Why is NodeList undefined in IE6/7?

4条回答
  •  星月不相逢
    2020-12-31 20:42

    "Duck Typing" should always work:

    ...
    
    if (typeof el.length == 'number' 
        && typeof el.item == 'function'
        && typeof el.nextNode == 'function'
        && typeof el.reset == 'function')
    {
        alert("I'm a NodeList");
    }
    

提交回复
热议问题