从另一个HTML文件引用元素id


Reference an element id from another HTML file

我有两个文件一个是index。php另一个是march。html,我想从march。html中获取员工姓名我设置id为

<h3 id="name">John Doe</h3>

如何从march。html中获取这个名字,然后放到index。php中。如果您想了解更多细节,例如本月员工,因此我需要从11个其他文件中获取一个名称,以便在index.php中引用它们。我试过在php中使用DomDocument但它显示出很多麻烦这里的代码只是因为

<?php
      $dom = new DomDocument();
      $dom->validateOnParse = true;
      $dom->loadHtml("march.html");
      $name = $dom->getElementById("name");
      print $name;
?>

使用nodeValue属性获取值:

<?php
      $dom = new DOMDocument();
      $dom->validateOnParse = true;
      $dom->loadHTML(file_get_contents("march.html"));
      $name = $dom->getElementById("name")->nodeValue;
      print $name;
?>

我将使用jQuery AJAX调用与专门的AJAX函数"load"来做到这一点

的例子:

$('#result').load('ajax/test.html #container');

jQuery加载API:http://api.jquery.com/load/