如何通过单击按钮包含 html 文件
How to include html file by clicking button
我有 4 个按钮,每个按钮都必须在我的索引中包含 html 文件.html
我的按钮:
<div class="btn-group btn-group-lg">
<button type="button" class="btn btn-primary" ng-click="changePage2Content('page2page1.html')">
Chapter 1
</button>
<button type="button" class="btn btn-primary" ng-click="changePage2Content('page2page2.html')">
Chapter 2
</button>
<button type="button" class="btn btn-primary" ng-click="changePage2Content('page2page3.html')">
Chapter 3
</button>
<button type="button" class="btn btn-primary" ng-click="changePage2Content('page2page4.html')">
Chapter 4
</button>
</div>
我的js:
<script cam-script type="text/form-script">
inject(['$scope',function($scope){
$scope.url = '';
function changePage2Content(path)
{
$scope.url = path;
}
}]);
</script>
我的div 必须显示包含的文件:
<div class="row" ng-include='url'>
</div>
简单的方法:使用 jQuery 的 .load()
<div class="row" id="resultWrapper"></div>
<button type="button" class="btn btn-primary" data-href="chapter-1.html">
Chapter 1
</button>
<button type="button" class="btn btn-primary" data-href="chapter-2.html">
Chapter 2
</button>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('button').on('click', function() {
$('#resultWrapper').load($(this).data('href'));
});
});
</script>
使用 Jquery 很简单:
$( "#result" ).load( "ajax/test.html" );
您可以在此处阅读有关它的更多信息:http://api.jquery.com/load/
相关文章:
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 导入jQuery脚本获胜'我不处理html文件
- 生成pdf或其他非html文件时的错误处理
- 如果使用javascript函数屏幕太小,我该如何更改HTML文件的背景色
- html文件中的script标记根本不起作用
- 从单独的html文件预览Javascript文本
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- Android在webview中加载带有javascript的html文件,得到Uncaught ReferenceEr
- 什么更好?使用iframe或jQuery之类的东西在外部网站中加载HTML文件
- 当我在浏览器中打开HTML文件时,javascript不起作用
- 如何在另一个html文件的框架中包含图像
- 压缩静态HTML文件中的JS和CSS
- 从HTML文件中的TypeScript(.ts)获取值
- 以HTML文件中的编码形式脱机存储图像
- ionic幻灯片框中的每张幻灯片都有不同的HTML文件
- 加载具有特定CSS的HTML文件
- 使用Gulp手柄部分编译为单个HTML文件
- 使用javascript检查服务器上是否存在html文件
- 在本地启动HTML文件
- javascript从选中的复选框中检索输入值,并在同一网页中显示多个html文件