0

こんにちはjquery達人私はこれに不慣れで、非常に困難な状況にあります。ここで、この課題で私を助けてもらえますか?それは私にとって非常に重要であり、私はここで立ち往生しています. これがシナリオです: 3 ページ (インデックス、メニュー、コンテンツ) インデックスにはメニューが含まれています menu.php にはリンクが含まれています 今度は、このリンクをクリックして、index.php 内の分割に content.php をロードします。 . それは可能ですか?私はフォローしようとしましたが、何かが欠けています。

// これは index.php です

<div>
<?php include 'menu.php'; ?>

 <p>load the content here:</p>
 <ol id="new-nav"></ol>
 </div>

 <script>
 $(document).ready(function(){         

 $("#test li").click(function (e) {

    // Stop the link from changing the page
    e.preventDefault();

    // Your jQuery code.

    $("#new-nav").load($(this).attr("href"));
 });

 });
 </script>

// これは menu.php です

 <div id="test">
 <li><a href="content.html">Content</a></li>
 </div>

// content.html は段落です

4

1 に答える 1

4

あなたはliを選択していて、それのhref属性を取得しようとしています:-)

これを試して

$("#test li a:first").click(function (e) {

    // Stop the link from changing the page
    e.preventDefault();

    // Your jQuery code.

    $("#new-nav").load($(this).attr("href"));

});

于 2012-11-14T08:04:19.490 に答える