2013-04-04 42 views
0

你好,你所有的程序員,以及我有一個jQuery標籤的問題。我使用jQuery的選項卡之間導航,和jQuery代碼如下所示:jquery選項卡,如何重定向?

$(document).ready(function() { 

//Default Action 
$(".tab-content").hide(); //Hide all content 
$("ul.vertical-tab li:first").addClass("active").show(); //Activate first tab 
$(".tab-content:first").show(); //Show first tab content 

//On Click Event 
$("ul.vertical-tab li").click(function() { 
    $("ul.vertical-tab li").removeClass("active"); //Remove any "active" class 
    $(this).addClass("active"); //Add "active" class to selected tab 
    $(".tab-content").hide(); //Hide all tab content 
    var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content 
    $(activeTab).fadeIn(); //Fade in the active content 
    return false; 
}); 

}); 

第一個選項卡始終是默認的,所以,當我第二個選項卡上工作,並將數據提交給外部PHP腳本,重定向總是返回我第一個(默認選項卡)。 我的重定向如下所示:header('Location:http://www.administrator.php');

$con=mysqli_connect("localhost","root","","database"); 
$firstname=$_POST['firstname']; 
$lastname=$_POST['lastname']; 

$sql="INSERT INTO student (firstname,lastname) VALUES('$firstname','$lastname')"; 

if (!mysqli_query($con,$sql)) 
    { 
    die('Error: ' . mysqli_error()); 
    } 
header('Location:http://www.administrator.php'); 
mysqli_close($con); 

,因爲我使用jQuery我不能用自己的地址重定向到所需的選項卡。說明:/

+1

我會更擔心你的代碼中的[sql注入攻擊](http://bobby-tables.com)漏洞。插入這些是比一些糟糕的選項卡更大的優先級。 – 2013-04-04 17:04:36

+0

哦,我並不擔心安全問題,因爲我正在爲大學課程寫這個項目,所以我只想工作...... – 2013-04-04 17:08:16

+0

大學課程與否,你會被建議讓它成爲一種習慣來擔心關於安全。 – Rohrbs 2013-04-04 17:16:19

回答

2

你可以做一個基於散列的查找,例如:

link: http://www.administrator.php/#secondtab

$firsttab = window.location.hash ? 
    $(window.location.hash) : 
    $("ul.vertical-tab li:first"); 
$.firsttab.addClass('active').show(); 

然後你只需要IDS爲你的標籤匹配(如id="secondtab"

+0

我很困惑,我應該寫代碼的第二部分? somwhere裏面這個jQuery代碼,作爲一個獨立的函數?? – 2013-04-04 17:14:59

+0

替換'$(「ul.vertical-tab li:first」)。addClass(「active」)。show();'用它。它至少會讓你開始 – 2013-04-04 17:35:49

相關問題