在我的代码中,我有一个 jquery 脚本,它具有下一页和上一页功能。 jquery 脚本加载 php 脚本来解析选定的页面。解析后的页面删除了一个名称为 postsArea 的 div,并将其放入 ID 为 wrap 的 div 中。目前,jQuery 脚本已设置为将 div postsArea 放入 div 包装中。我想要做的是将 div postsArea 放入一个带有 id news 的 iframe 中。
JQuery :
$('document').ready(function () {
var $wrap = $('#wrap'),
page = 1;
$('#next').on('click', function () {
getPage(++page);
});
$('#prev').on('click', function () {
getPage(--page);
});
var getPage = function (page) {
$wrap.load('proxy.php?page=' + page + ' #postsArea');
};
getPage(page);
});
PHP :
<?php
include( 'site/simple_html_dom.php');
$html=file_get_html( 'http://roosterteeth.com/home.php?page=' . $_GET["page"]);
echo $html;
?>
HTML :
<body>
<div id="wrap">
</div>
<button type="button" id="next">Next</button>
<button type="button" id="prev">Previous</button>
</body>
非常感谢您的帮助,感谢您抽出宝贵时间。
最佳答案
iframe 基本上只是一个能够执行 http 查询的子窗口。您只需将 iframe 元素值的“src”属性设置为正确的 url。
$("iframe").attr("src",'proxy.php?page=' + page + ' #postsArea');
关于javascript - 将 iframe 与 jquery 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20744781/