javascript - 根据父页面上的按钮单击在子页面内加载 div
问题描述
这是我要完成的工作的精简示例。我有两个页面,父页面(index.html)和子页面(child.html)。子页面有多个子 html 页面,这些子页面使用 jQuery 在子页面 div 容器内基于 child.html 页面上的按钮单击动态加载,效果很好,但我需要做的是基于 child.html 加载子页面index.html 中的父按钮单击。谁能解决这个问题?
索引.html
<body>
<div class="container-fluid">
<div class="row">
<ul>
<h1>Main Nav</h1>
<!--When this button is clicked, it opens child.html in a new tab and must load pageone.html inside the #shared-page div of child.html page and the corresponding <li> item in child.html page should be active-->
<li><a href="child/child.html" class="share-one" target="_blank">Page One</a></li>
<!--When this button is clicked, it opens child.html in a new tab and must load pagetwo.html inside the #shared-page div of child.html page and the corresponding <li> item in child.html page should be active -->
<li><a href="child/child.html" class="share-one" target="_blank">Page Two</a></li>
</ul>
</div>
</div>
</body>
child.html
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<ul>
<h1>Left Nav</h1>
<li><button class="share-one" type="button">Page One</button></li>
<li><button class="share-two" type="button">Page Two</button></li>
</ul>
</div>
<div class="col-md-9">
<div id="shared-page"></div>
</div>
</div>
</div>
</body>
jQuery动态加载共享页面
$(document).ready(function(){
$(".share-one").on("click",function(){
$("#shared-page").load("https://www.hostnanny.tk/test/shared/shareone.html");
});
$(".share-two").on("click",function(){
$("#shared-page").load("https://www.hostnanny.tk/test/shared/sharetwo.html");
});
});
解决方案
推荐阅读
- javascript - 将图像 URI 转换为文件或 Blob
- javascript - 如何在单个输出页面上打印 1-3 张图像?
- swift - Swift/Cocoa:launchApplication(at:options:configuration:) 和捕获错误
- if-statement - netlogo中的逻辑问题
- sql - 使用正则表达式验证一列只有数字
- r - 删除图例名称
- asp.net-web-api - 您是否应该将 Newtonsoft 添加到 WebAPI 项目或使用嵌入 WebAPI 的 Newtonsoft?
- amazon-dynamodb - 通过在 EMR 上运行的 PySpark 中的 Glue 数据目录访问 DynamoDB 时,绝对 URI 异常中的相对路径
- python - 需要帮助将源和目标端口号输出给用户,使用 Python 和 dpkt 从 pcap 文件中读取
- simulink - 一个循环后输出力为零