2014-02-15 23 views
-2

我無法在互聯網上找到我想要的東西。如何只用url加載隱藏的內容框?

我有這個div,在我的index.php

<div id="navigatie_box" class="about"> 
    <h1 class="navigate_title">About</h1> 
    <div class="about_image"></div> 
</div> 

在點擊我這個隱藏內容框加載內容我在子圖已經greated,內容/ about.php

<div class="content"></div> 

點擊內容框顯示並加載其中的內容/ about.php。

這是我使用該

$(document).ready(function(){ 
    /* about click */ 
    $('.about').click(function() { 
    $('.about').hide("fast"); 
    $('.work').hide("fast"); 
    $('.cv').hide("fast"); 
    $('.contact').hide("fast"); 
    $(".content").slideDown("fast"); 
    $(".content").load("content/about.php"); 
    }); 

我現在想的是在我的網址位置的JavaScript,所以如果我型www.example.com/about,隱藏的內容框中顯示了和負載其中的內容/ about.php。

我認爲這一個noob問題,但我真的不能找到它了!

我希望你能幫助我。

+0

一些改善「所以,如果我輸入www.example。 com/about「你是什麼意思?如果你在哪裏輸入? –

+0

我的意思是在我的瀏覽器中。 – user3313356

回答

0

首先,您必須在.htaccess 中創建重寫規則,以在遇到www.example.com/about時指向index.php文件。

還可以創建規則,在.htaccess中發送一個GET參數發言權「頁」。 因此,當我們打電話給www.example.com/about時,它應該重定向,如www.example.com/index.php?page=about。

現在index.php文件,你將不得不檢查$ _GET [「頁」]被設置爲比你將不得不只顯示所需要的內容。

+0

我在本地主機的工作,像這樣:本地主機/例如,在這個地圖是我的index.php和我一樣的子圖的內容/ about.php 那是相關的嗎? – user3313356

0

不知道要明白你的問題,但我想你想這樣的事情:

var page = window.location.pathname.split("/").pop(); 

$(document).ready(function() { 
    /* about click */ 
    $('.about').click(function() { 
     $('.about').hide("fast"); 
     $('.work').hide("fast"); 
     $('.cv').hide("fast"); 
     $('.contact').hide("fast"); 
     $(".content").slideDown("fast"); 
     $(".content").load("content/" + page + ".php"); 
    }); 
}); 

這是基本的片段,並需要一定

+0

我現在只是基本的jquery腳本。 它加載指定div中的內容,而不更改url或其他內容。 所以我想要的是,如果我鍵入www.example.com/about它加載content/about在指定的div。無需點擊按鈕。關於我的index.php 我在本地主機也行,像這樣:本地主機/例如,在這個地圖是我的index.php和/我supmaps如內容about.php – user3313356

+0

ü不明白什麼?我想讓你清楚:) – user3313356