【发布时间】:2020-07-15 04:25:04
【问题描述】:
我想问我如何只“drawTable”一次并切换它?我不想每次单击元素时都调用我的 ajax。当我单击 tableA 时,drawTable() 加载时间过长,并且 tableA 的类已经首先切换,因为我的 tableA 的 onclick 上有另一个 toggleSetting() 函数,我如何确保它同时更改?
$("#tableA").on("click", (function () {
$.ajax({
type: "POST",
url: "Acc.ashx",
success: function (output) {
try {
output = JSON.parse(output);
DrawATable(output);
}
catch (ex) {
alert("error");
$('#tableA').empty();
}
}
, complete: function (data) {
isClicked = false;
}
}).then($('#tableSAOnce').toggleClass('accordion accordion2'))
}));
function toggleSetting(setting, ctrl) {
var stt = document.getElementById(setting);
if (stt.style.display == 'none') {
stt.style.display = '';
ctrl.className = "accordion2";
}
else {
stt.style.display = 'none';
ctrl.className = "accordion";
}
}
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table id="tableAOnce" class="accordion" onclick="toggleSetting('toggleA',this)">
<tr>
<td align="left">TableA</td>
</tr>
</table>
</td>
</tr>
<tr style="display:none;" id="toggleA" >
<td>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" id="tableA"></table>
</td>
</tr>
</table>
【问题讨论】:
标签: javascript html jquery asp.net