2011-11-01 34 views
1

上午所有,開放jQuery的彩盒從ASP.NET MVC部分

我有一個ASP.Net MVC應用程序,並在頁面上的一個我有上有按鈕,通過AJAX加載表格打開'詳細信息'colorbox。我綁定了所有按鈕以在頁面加載中使用jQuery顏色框插件,但是當我重新加載表格時,這些按鈕不再起作用,因爲它們需要重新綁定。因此我打算直接調用colorbox。

我有以下代碼:

<td><button class="button" type="button"  onclick="$.colorbox({href:"@Url.Action("ShowReviewFeedbackDetails", "Review", new { reviewFeedbackId = reviewfeedback.ReviewId, subjectId = reviewfeedback.SubjectArea.Id })", transition: "elastic", iframe: true, overlayClose: true, width: 650, height: 400, scrolling: false});">Details</button></td> 

當我點擊按鈕,我得到一個JavaScript語法錯誤。我也得到了錯誤,如果我刪除的助手,只是硬編碼的URL,例如:

<td><button class="button" type="button" onclick="$.colorbox({href:"www.google.com", transition: "elastic", iframe: true, overlayClose: true, width: 650, height: 400, scrolling: false});">Details</button></td> 

顏色框上工作的其他網頁得很好,我沒有重裝動態調用它們不過他們只是有按鈕colorBoxStd作爲一個階級和我使用內$(document).ready

$(".colorBoxStd").colorbox({ transition: "elastic", iframe: true, overlayClose: true, width: 650, height: 400, scrolling: false }); 

任何想法,這個代碼將不勝感激,因爲我拉我的頭髮用這個..

感謝, Ĵ

+0

在jQuery中捕獲按鈕單擊事件並從那裏調用colorbox。給你更多的調試選項 – Ivo

回答

2

你沒有正確地轉義onclick屬性和更具體的href屬性:

<td><button class="button" type="button" onclick="$.colorbox({href:'@Url.Action("ShowReviewFeedbackDetails", "Review", new { reviewFeedbackId = reviewfeedback.ReviewId, subjectId = reviewfeedback.SubjectArea.Id })', transition: 'elastic', iframe: true, overlayClose: true, width: 650, height: 400, scrolling: false});">Details</button></td> 

我更換了周圍href屬性單引號的雙引號。雙引號也被transition屬性的單引號替換。

這就是說,我會簡單地使用.delegate()(或.live())方法來訂閱click事件,以便即使您使用AJAX替換內容,它也能正常工作。這樣你將有單獨的標記和JavaScript,你不需要把你的標記變成它當前的東西(我很難找到一個合適的形容詞來形容:-))

+0

這是排序它..事實證明,這是我的愚蠢,這是問題。 –