查找没有与之关联的特定事件的元素

时间:2018-04-15 15:02:18

标签: javascript

使用javascript - 如何在一组共享相同className的元素中找到一个元素,该元素没有附加特定事件。

var items = document.getElementsByClassName("myInputs");

如何查询结果 - items以找出哪些元素没有附加keypressed事件?

1 个答案:

答案 0 :(得分:0)

一个有效的解决方案(编辑:如果事件已根据评论和explained here中的指针附加了addEventListener,则此功能无效:

var items = document.getElementsByClassName("myInputs");
var elementsWithoutKeyPress = Array.prototype.slice
    .call(items)
    .filter(function(item) {
        return !item.onkeypress;
    });

编辑(来自评论建议):Array.prototype.slice.call是(或多或少)在非数组容器上调用Array方法的习惯用法。并here you have the documentation of filter function

相关问题