我的表格中每行中的第一个<td>
都是可点击的。单击它时,它应该展开 - 在<div>
中显示一些数据,再次单击时,必须隐藏<div>
。到目前为止,我已经尝试this,但我无法隐藏它。 Plz根据附带的样本提供您的建议。
感谢。
答案 0 :(得分:1)
尝试,
$('#tbdyId').on('click', 'a', function (event) {
event.preventDefault();
var $currentRow = $(this).closest("tr");
console.log($currentRow);
var $sib = $currentRow.next().children().find('div');
console.log("sib: ");
console.log($sib);
if ($sib.is('.expanded')) {
$sib.closest('tr').toggle();
} else {
var newRow = $currentRow.after("<tr><td colspan='5'>" +
"<div align='center' class='expanded'> <table border='0'>" +
"<tr><td> some data </td></tr></table></div>" +
"</td></tr>");
}
});