简体   繁体   English

jQuery add.EventListner不是函数DoubleClick Banners

[英]Jquery add.EventListner is not a function Double Click Banners

I have built some HTML5 banners for use with google Double Click. 我已经建立了一些HTML5横幅广告,可用于Google Double Click。 I have 2 CTA's on the banner and so I have used the below code which is a slightly amended version of the original double click code. 我的横幅广告上有2个CTA,因此我使用了以下代码,该代码是原始双击代码的略微修改版本。 (I comma seperated 2 ID's rather than use one). (我用逗号分隔2个ID,而不用一个)。

function bgExitHandler(e) {
    Enabler.exit('Click for PI');
}
document.querySelectorAll("#click_for_pi, #found-out-more").addEventListener('click', bgExitHandler, false);

I am however getting the below error in the browser: 但是,我在浏览器中收到以下错误:

TypeError: document.querySelectorAll(...).addEventListener is not a function TypeError:document.querySelectorAll(...)。addEventListener不是一个函数

This is my first time using Double click and HTML5 banners so I am not quite sure the correct methods. 这是我第一次使用DoubleClick和HTML5标语,因此我不太确定正确的方法。

querySelectorAll returns a collection of matched DOM nodes. querySelectorAll返回匹配的DOM节点的集合 You need to iterate over it and bind the event individually on each element. 您需要对其进行迭代,并将事件分别绑定到每个元素上。

Returns a list of the elements within the document (using depth-first pre-order traversal of the document's nodes) that match the specified group of selectors. 返回与指定选择器组匹配的文档中的元素列表(使用文档节点的深度优先顺序遍历)。 The object returned is a NodeList. 返回的对象是NodeList。

function bgExitHandler(e) {
    Enabler.exit('Click for PI');
}
var els = document.querySelectorAll("#click_for_pi, #found-out-more");

for (var i = 0; i < els.length; i++) {
    els[i].addEventListener('click', bgExitHandler, false);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM