Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jquery获取每个文件中的p标记数_Javascript_Jquery - Fatal编程技术网

Javascript 如何使用jquery获取每个文件中的p标记数

Javascript 如何使用jquery获取每个文件中的p标记数,javascript,jquery,Javascript,Jquery,我正在像这样将html文件加载到div var j1 = $('<div class = "cl1">').load('components/1.html'); var j2 = $('<div class = "cl2">').load('components/2.html'); var j3 = $('<div class = "cl3">').load('components/3.html'

我正在像这样将html文件加载到div

var j1 = $('<div class = "cl1">').load('components/1.html');
                var j2 = $('<div class = "cl2">').load('components/2.html');
                var j3 = $('<div class = "cl3">').load('components/3.html');                


            $("#search_content").append(j1);
            $("#search_content").append(j2);
            $("#search_content").append(j3);
var j1=$('').load('components/1.html');
var j2=$('').load('components/2.html');
var j3=$('').load('components/3.html');
$(“#搜索内容”)。追加(j1);
$(“#搜索内容”)。追加(j2);
$(“#搜索内容”)。追加(j3);

我想得到每个文件中p标签的计数。提前感谢。

您可以在包含文档的每个元素中搜索
p
标记。在给定的代码片段中:

var j1 = $('<div class = "cl1">').load('components/1.html', function() {//after content loaded
    var ptags = j1.find("p").length
});
var j1=$(“”).load('components/1.html',function(){//加载内容后
变量ptags=j1.查找(“p”).长度
});

更新:如果您希望同时使用这三个选项,他应该使用Promissions-有关加载带有Promissions的内容,请参阅,所以您需要计算每个文件的数量?加载一个文件,计算段落数,然后加载另一个,然后再次计算? 最简单的计算方法是:

function count_pars(){
var n=0;
$('p').each(
function(){
n=n+1;
})
//do stuff 
}
然后像这样使用:

$("#search_content").append(j1);
count_pars();

这会起作用,但是OP如何将这三个计数一起使用呢?