我在html中有一個手風琴,頭文件onclick調用函數initTable。jquery回調遇到問題
<script type="text/javascript">
$(document).ready(function()
{
$('.accordion ul li h1').click(function()
{
document.getElementById('processing').innerHTML = "Processing...";
document.body.style.cursor = 'Wait';
$(this).parent().parent().find('.ac:visible').slideToggle().parent().removeClass('active');
if ($(this).next().is(':hidden'))
{
$(this).next().slideToggle().parent().addClass('active');
}
});
});
</script>
</head>
<body>
<div id=processing></div>
<div class="wrapper">
<div class="accordion">
<ul>
<li>
<h1 onclick=initTable("Anticoag")>Anticoag</h1>
<div class="ac">
<div id="AnticoagTable" width="100%">Loading...</div>
</div>
</li>
initTable命中服務器以獲取數據並創建一個DataTable,這需要幾秒鐘的時間。
我想要做的是在發生initTable調用之前,將我的div id ='processing'設置爲「正在處理...」。
眼下發生的事情是,它等待表數據回來,那顯示「正在處理......」
我試圖改變我的H1到的onclick = TEST1(類別),與此代碼。但由於某種原因,我的initTable函數甚至沒有被調用。不知道它是語法還是我完全錯誤地使用它。
function test1(category)
{
test2(category, function()
{
initTable(category);
});
}
function test2(category)
{
alert("test2");
document.getElementById('processing').innerHTML = "Processing...";
document.body.style.cursor = 'Wait';
}
通過請求加入initTable功能 功能initTable(類別){ 如果(gsCategory === 「」)gsCategory =類別; else if(gsCategory == category)gbToggle =!gbToggle; else gbToggle = false;
gsCategory = category;
if (gbToggle === false) {
gsCategory = category;
var select = document.forms[0].selFacility;
var facility = select.options[select.selectedIndex].value;
var patJson = getJson(facility, category);
document.getElementById('processing').innerHTML = "Done...";
document.body.style.cursor = 'Default';
var anOpen = [];
var sImageUrl = "../images/";
makeTable(category);
var oTable = $('#' + category).dataTable({
"bProcessing": false,
"bDestroy": true,
"aaData": patJson,
"bAutoWidth": false,
"aoColumns": [{
"mDataProp": null,
"sClass": "control center",
"sDefaultContent": '<img src="' + sImageUrl + 'details_open.png' + '">',
"sWidth": "5%"
}, {
"mDataProp": "S_PAT_NAME",
"sWidth": "30%"
}, {
"mDataProp": "S_AGE",
"sWidth": "15%"
}, {
"mDataProp": "S_FIN",
"sWidth": "30%"
}, {
"mDataProp": "S_ROOM_BED",
"sWidth": "20%"
}]
});
$('#' + category + ' td.control').live('click', function() {
var nTr = this.parentNode;
var i = $.inArray(nTr, anOpen);
if (i === -1) {
$('img', this).attr('src', sImageUrl + "details_close.png");
var nDetailsRow = oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
$('div.innerDetails', nDetailsRow).slideDown();
anOpen.push(nTr);
} else {
$('img', this).attr('src', sImageUrl + "details_open.png");
$('div.innerDetails', $(nTr).next()[0]).slideUp(function() {
oTable.fnClose(nTr);
anOpen.splice(i, 1);
});
}
});
} //gbToggle = false
}
你的'initTable'函數是什麼樣的? – YoannM 2013-02-10 20:11:37