1

我一直在四处寻找,没有什么能完全符合我的需要。这是我要完成的工作:

<a href="">TSConfig</a> <!-- When clicked, it loads tsconfig.php which contains a form and some php code into #main_content -->
<a href="">MVSN</a> <!-- When clicked, it loads mvsn.php which contains a form and some php code into #main_content -->
<a href="">Fulfillment</a> <!-- When clicked, it loads maint_fulfil.php which contains a form and some php code into #main_content -->

<div class="grid_3" id="main_content">

    <!-- PHP CONTENT TO LOAD HERE -->

</div>

我尝试了 JQuery 示例的不同变体来尝试使这项工作正常进行,但是大多数示例都包含从 .php 文件中提取 id 并以某种方式操作 url,这是我不想做的事情。

非常感谢,我希望我解释正确。

4

2 回答 2

4

将您的 html 更改为此...

<a class="ajax-link" href="tsconfig.php">TSConfig</a> <!-- When clicked, it loads tsconfig.php which contains a form and some php code into #main_content -->
<a class="ajax-link" href="mvsn.php">MVSN</a> <!-- When clicked, it loads mvsn.php which contains a form and some php code into #main_content -->
<a class="ajax-link" href="maint_fulfil.php">Fulfillment</a> <!-- When clicked, it loads maint_fulfil.php which contains a form and some php code into #main_content -->

<div class="grid_3" id="main_content">

    <!-- PHP CONTENT TO LOAD HERE -->

</div>

这是为您加载所需页面的脚本...

$(function() {
    $("a.ajax-link").on("click", function(e) {
        e.preventDefault();
        $("#main_content").load(this.href);
    });
});

我将类添加ajax-link到每个链接,以便您可以将上述脚本应用于它们,但不能应用于页面上的任何其他链接。

于 2013-09-19T13:59:13.897 回答
0

jQuery.load

最后一个例子也很清楚:

$( "#feeds" ).load( "feeds.php", { limit: 25 }, function() {
  alert( "The last 25 entries in the feed have been loaded" );
});
于 2013-09-19T13:59:38.363 回答