如何访问其他html页面的元素

How to access the elements of other html page?

本文关键字:html 元素 其他 何访问 访问      更新时间:2023-09-26

我想访问具有相同域的其他html页面的主体的元素(通过id)。这可能吗?
我应该使用哪个函数?

当你正在使用AJAX,你想使用加载页面片段$.load:

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

在这种情况下,访问页将把#result作为元素的id。新的一页,你说有ajax/test.html的位置。在这种情况下,具有#container的元素将被加载到调用页面的#result中。

使用规则:

  1. 主叫页面和被叫页面应该在同一个域中
  2. 如果在不同的域,它应该有标题:Access-Control-Allow-Origin: * .