如何使用jQuery在我的页面中查找谷歌广告
How to find Google ads inside my page using jQuery?
我试图在一个html页面中找到所有谷歌广告:
jQuery( "object" ).each(function (index){
if (this.id.contains("google")) {
var h = jQuery(this).height();
var w = jQuery(this).width();
console.log("h:" + h + ",w: " + w);
}
我得到这个错误:不能调用方法包含未定义的
有人能解释为什么吗?
我该如何修复(或以正确的方式进行)?
谢谢。
错误消息为"无法调用未定义的方法包含"。由于您正在调用this.id.contains
,这意味着this.id是未定义的,因此,它没有id属性。
Javascript没有.contains()
方法。您可以使用.indexOf():
jQuery( "object" ).each(function (index){
if (this.id.indexOf("google") >= 0)
var h = jQuery(this).height();
var w = jQuery(this).width();
console.log("h:" + h + ",w: " + w);
}
});
我在做类似的事情时发现了你的问题:我使用的jquery选择器是这样的:
alert($('[class*="google"]').length)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="bottomLeaderBoard googleAds">
the content ...
</div>
类可以被替换。。我希望它能有所帮助:)
相关文章:
- 在谷歌地图上查找最近的大头针
- 如何使用谷歌地图几何库查找两点之间的距离
- AngularJS与角度谷歌地图:添加标记通过fomr和查找我
- 在谷歌日历API的events.list的响应中查找日历所有者的电子邮件
- jQuery 自动完成与谷歌地图地址查找
- 谷歌地图-查找给定半径内的所有标记Javascript/Php
- 谷歌地图:按Id查找多边形
- 在谷歌地图中查找给定英里/公里的半径
- 标记没有出现在谷歌地图上使用wp_query查找点
- 如何在谷歌地图中使用邮政编码查找位置
- 谷歌分析-如何在jQuery中查找上一页的URL
- 在谷歌网站上查找一些文本
- 找到纬度和经度从起点的路线查找在谷歌地图
- 查找谷歌地图实例
- angularJS使用angular谷歌地图查找位置/地名
- 使用谷歌地球API查找景观结构
- 我的谷歌地图距离查找器不能正常工作与SSL
- 谷歌铬-如何限制Javascript's window.查找特定DIV
- 如何使用jQuery在我的页面中查找谷歌广告
- 在页面上查找谷歌标记的位置