【发布时间】:2016-09-27 16:47:00
【问题描述】:
您好,我正在使用 bootstrap 构建一个简单的网站。
我想要一些按钮来改变我的iframe 的src 参数,它显示pdf file。例如,当我点击button 2 时,我想在iframe 中显示pdf2。
这是我在 html 中的内容:
<div class="btn-group" role="group" >
<button id="1" type="button" class="btn btn-default">Report 1</button>
<button id="2" type="button" class="btn btn-default" >Report 2</button>
<button id="3" type="button" class="btn btn-default">Report 3</button>
</div>
<div class="embed-responsive embed-responsive-16by9">
<iframe id="iframe" class="embed-responsive-item" src="reports\Report1.pdf"></iframe>
</div>
这在我包含的单独的js 文件中。如果我犯了一些非常明显的错误,请不要那么难,因为我是新手。我尝试使用我在此处找到的一些功能来强制重新加载网站。它不起作用
$(document).ready(function(){
$("#1").click(function(){
$("#iframe").attr("src", 'reports\Report1.pdf');
$("#iframe").contentWindow.location.reload(true);
});
$("#2").click(function(){
$("#iframe").attr("src", 'reports\Report2.pdf');
$("#iframe").contentWindow.location.reload(true);
});
$("#3").click(function(){
$("#iframe").attr("src", 'reports\Report3.pdf');
$("#iframe").contentWindow.location.reload(true);
});
});
【问题讨论】:
标签: javascript jquery pdf iframe