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 使用JS/jQuery/Ajax从.html文件获取document.title?_Javascript_Jquery_Html_Ajax - Fatal编程技术网

Javascript 使用JS/jQuery/Ajax从.html文件获取document.title?

Javascript 使用JS/jQuery/Ajax从.html文件获取document.title?,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我有索引页(菜单),用于在同一目录中的其他.html页面之间导航 结构如下所示: index.html 000001.html 000002.html 000003.html 000004.html ... header.html bottom.html 000001 SomeFile.png ... 000002 SomeFile.zip ... ... 我需要从index.html中的所有******.html文件中获取document.title UPD:

我有索引页(菜单),用于在同一目录中的其他.html页面之间导航

结构如下所示:

index.html
000001.html
000002.html
000003.html
000004.html
...
header.html  
bottom.html  
000001
   SomeFile.png
   ...
000002
   SomeFile.zip
   ...
...
我需要从index.html中的所有******.html文件中获取
document.title


UPD:忘记在中包含其他文件和文件夹,例如抱歉。

下面的代码从HTMLs获取标题

$(document).ready(function () {
    var files = ['000001.html', '000002.html', '000003.html'];

        for (i = 0; i <= files.length; i++) {
            jQuery.get(files[i], function (data) {

                var htmlstr = $.parseHTML(data);
                //alert($(htmlstr).filter('title')[0].text);
               $('#test').append($(htmlstr).filter('title')[0].text);
            });
        }
});

<div id="test"></div>
$(文档).ready(函数(){
var files=['000001.html','000002.html','000003.html'];
对于(i=0;我签出)
您可以使用以下内容使用彼此页面的标题填充页面:

$(function(){
  var numberOfHtmlDocs = 10; // this will search through 000001.html ... 000010.html
  var numberFormat = function(number, width) { // useful for padding numbers with 0's
    return new Array(width + 1 - (number + '').length).join('0') + number;
  }

  for(i = 1; i <= numberOfHtmlDocs; i++) { // loop through for each document
    var paddedInt = numberFormat(i, 6); // change '1' to '000001', etc.
    $('body').append('<h3></h3>'); // Add a container to put the value in
    $('h3:last-child').load(paddedInt + '.html title'); // Set the text of the container that was just added to be the value of the title
  }
});
$(函数(){
var numberOfHtmlDocs=10;//这将搜索000001.html…000010.html
var numberFormat=function(number,width){//用于用0填充数字
返回新数组(宽度+1-(数字+“”).length.join('0')+数字;
}

对于(i=1;您需要一次从每一页获取标题吗?还是仅从当前页获取标题?document.title是一次检索页面标题的正确代码。@oompahlumpa每一页。这些文件有多少,它们有多大?因为如果您仔细考虑,您必须将这些文件中的每一个加载到内存中,获取<代码>title
元素,然后获取下一个,等等。可能会有大量的网络流量…同意@Mike的说法-我会一次性收集标题作为构建或部署步骤,而不是每次请求索引页时都动态收集。谢谢,然后我需要依次将它们打印到不同的div中。我该怎么做呢将警报语句替换为下面类似于$(YOURJQUERYSELECTOR).append($(htmlstr).filter('title')[0].text);