2011-07-01 130 views
0

我在我的MVC3解決方案中使用jQuery選項卡。問題是,當我在這些標籤中插入一個鏈接時,我無法用jQuery控制這個鏈接?!jQuery點擊事件不工作在jQuery標籤頁

這裏是我的代碼:

主要標籤細分頁:

<div id="tabContainer"> 
<ul> 
    <li>@Html.ActionLink("Tab 1", "DetailFooterTab1", "MyController")</li> 
    <li>@Html.ActionLink("Tab 2", "DetailFooterTab2", "MyController")</li> 
    <li>@Html.ActionLink("Tab 3", "DetailFooterTab3", "MyController")</li> 
</ul> 

這個腳本:

$("#tabContainer").tabs(); 

在我TAB3頁我有這樣的代碼:

<a href="#" id="buttonTest">Test</a> 

<script type="text/jscript"> 

$("#buttonTest").click(function() { 
    alert('I am a link in the Tab 3 page'); 
}); 

</script> 

這些jQuery選項卡的作品。我的意思是我可以點擊其中的一個,系統顯示相應的標籤(並隱藏其他標籤內容)。但是當我點擊測試鏈接時,什麼都沒有發生!任何想法?

+0

是你的href動態。 – kobe

回答

0

你把你的$代碼(文件)。就緒?

$(document).ready(function(){ 
    $("#buttonTest").click(function() { 
    alert('I am a link in the Tab 3 page'); 
    }); 
}); 

或者如果該元素在dom後面添加。你可以使用現場活動 像

$("#buttonTeest").live('click',funciton(){ 
    alert('I am a link in the Tab 3 page'); 
}); 
+0

你是對的。 **活**保存了我的一天:) – Bronzato

+0

對我也很好;) –

0

試試這個,

$("#buttonTest").click(function (e) { 
    e.preventDefault(); 
    alert('I am a link in the Tab 3 page'); 
}); 
0

如果你在運行時使用添加他們住在一起,而不是綁定

$('#buttonTest').live('click', function() { 
e.preventDefault(); 
    alert('I am a link in the Tab 3 page'); 
});