链接到ajax div

时间:2012-04-08 01:28:49

标签: jquery html css ajax

好的家伙希望我能有效地解释这一点,所以这里就是。

我有一个无序列表,其中每个列表项在我的“服务”页面上通过jquery点击html页面加载到div中。

基本上在首页上我有几个链接,当点击一个链接时,我需要它去“服务”并在div中看到相应的html页面。

以下是代码如何:

服务页面:

<ul id="service-nav">

            <li><a id="interlocking" href="#">Interlocking</a></li>
            <li><a id="pool-backfill" href="#">Pool Backfill</a></li>
            <li><a id="poured-concrete" href="#">Poured Concrete</a></li>
            <li><a id="parging" href="#">Parging</a></li>
            <li><a id="custom-land" href="#">Custom Landscaping</a></li>
            <li><a id="snow-rem" href="#">Snow Removal</a></li>
            <li><a id="excavation" href="#">Excavation</a></li></ul>
      </ul>

    <div id="right-area"> <!-- This is where we load the relevant html's -->
    </div>

首页:

        <ul>
            <li><a href="services.php?token=interlocking">Interlocking</a></li>
            <li><a href="services.php?token=pool-backfill">Pool Backfill</a></li>
            <li><a href="services.php?token=poured-concrete">Poured Concrete</a></li>
        </ul>

这是我的jQuery供你参考:

<script type="text/javascript">
$(document).ready(function() {

    $(function(){ 
        var token = window.location.toString().split("=")[1]; 

        $("#" + token).click(); 

        });​


    $('#interlocking').click(function() {
        $('#right-area').load('http://romanstonedesigns.com/new/services/interlocking.php', function() {
        });
    });

    $('#pool-backfill').click(function() {
        $('#right-area').load('http://romanstonedesigns.com/new/services/pool-backfill.php', function() {
        });
    });

    $('#poured-concrete').click(function() {
        $('#right-area').load('http://romanstonedesigns.com/new/services/poured-concrete.php', function() {
        });
    });

    $('#parging').click(function() {
        $('#right-area').load('http://romanstonedesigns.com/new/services/parging.php', function() {
        });
    });

    $('#custom-land').click(function() {
        $('#right-area').load('http://romanstonedesigns.com/new/services/custom-landscaping.php', function() {
        });
    });

    $('#excavation').click(function() {
        $('#right-area').load('http://romanstonedesigns.com/new/services/excavation.php', function() {
        });
    });

    $('#snow-rem').click(function() {
        $('#right-area').load('http://romanstonedesigns.com/new/services/snow-removal.php', function() {
        });
    });







});

</script>

1 个答案:

答案 0 :(得分:0)

好吧,假设我们想要显示互锁页面,所以你的首页应该是这样的:

1

<ul>
        <li><a href="services.php?token=Interlocking">Interlocking</a></li>
    </ul>

2.在您的服务页面中,jquery代码应为:

  <script type="text/javascript">


$(function(){ 




    $('#interlocking').click(function() {
    $('#right-area').load('http://romanstonedesigns.com/new/services/interlocking.php', function() {
    });
});

$('#pool-backfill').click(function() {
    $('#right-area').load('http://romanstonedesigns.com/new/services/pool-backfill.php', function() {
    });
});

$('#poured-concrete').click(function() {
    $('#right-area').load('http://romanstonedesigns.com/new/services/poured-concrete.php', function() {
    });
});

$('#parging').click(function() {
    $('#right-area').load('http://romanstonedesigns.com/new/services/parging.php', function() {
    });
});

$('#custom-land').click(function() {
    $('#right-area').load('http://romanstonedesigns.com/new/services/custom-landscaping.php', function() {
    });
});

$('#excavation').click(function() {
    $('#right-area').load('http://romanstonedesigns.com/new/services/excavation.php', function() {
    });
});

$('#snow-rem').click(function() {
    $('#right-area').load('http://romanstonedesigns.com/new/services/snow-removal.php', function() {
    });
});

    var token = window.location.toString().split("=")[1]; 
    $("#" + token).click(); 

    });

再见!