本文介绍了$(...).每个不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Web控制台在页面上的所有 h2 标签中获取文本.
I'm trying to get the text inside all h2 tags on a page, using the web console.
我发现所有尝试使用的东西
All I've found says to use each, I've tried
var anArray = [];
$('h2').each( function(i,e) {
anArray.push($(e).innerHTML);
});
但是它返回TypeError: $(...).each
不是函数.
我也尝试使用
$.each('h2', function(i,e) {
anArray.push($(e).innerHTML);
});
但是,我得到的只是TypeError: $.each
是不是函数?
But again, all I get is TypeError: $.each
is not a function?
推荐答案
1)粘贴:
var script = document.createElement('script');
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
在您的控制台上(包括jQuery)
on your console (includes jQuery)
2)等待1秒钟并粘贴:
var h2Arr = [];
$('h2').each( function() {
h2Arr.push($(this).html());
});
现在,该页面的h2标签的所有内容都应存储在h2Arr中
Now, all contents of h2 tags of that page should be stored into h2Arr
这篇关于$(...).每个不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!