我想申請一個jQuery tabs
做一個動態加載的內容。問題是在加載容器之前應用了tabs
函數,因此我看不到渲染的選項卡。調試我不能等待一段時間,它可以成功運行。如何等待一個要加載的元素才能應用JQuery功能
我的背景是一個主/細節網格,將細節顯示爲可展開的行。每次點擊一個網格行時,我都會通過ajax詢問詳細信息到另一個名爲mypage.aspx
的頁面,並將收到的數據放到一個名爲contentDetail
的div
,這實際上是一個動態生成的tr
。一旦獲得了數據,我想將tabs
函數應用於mypage.aspx內容。
這裏是我的代碼:
var html = '<tr id="newRow"><td colspan="4"><div id="contentDetail"></div></td></tr>';
$('#mygrid tr').each(function() {
$(this).on('click', function() {
// I create a row on the fly and append it next to the clicked row
// ...
// I load the contents
$('#contentDetail').load('mypage.aspx #div1', { data: '123' }, function (response, status, xhr) {
if (status == "error") {
// ERROR
}
});
// Here I want to apply the tabs
$('#contentDetail').ready(function() {
$('.tabs').tabs();
});
});
更新:
$.when($('#contentDetail').load('mypage.aspx #div1', { data: '123' }, function (response, status, xhr) {
if (status == "error") {
// ERROR
}
})).then($.getScript('Scripts/function.js'));
function.js: $('#tabs').tabs();
不工作謝謝。 – anmarti 2013-03-12 13:46:26