我已经关注了html:
<tr>
<td class="link" onClick="detil_iklan(this)">AD2188914</td>
<td>Seluruh Zona 468x60 - Global Gambar</td>
<td>41.100.000</td>
<td>4.440.100</td>
<td>0.005</td>
<td>Rp. 1.250.000</td>
</tr>
<tr class="border_bottom detil_iklan" style="display:none">
<td colspan="6">AD2188914</td>
</tr>
我已经关注了javascript:
function detil_iklan(e) {
var parent = e.parentNode;
var next = parent.nextSibling;
if (next.style.display == 'none') {
next.style.display = '';
} else {
next.style.display = 'none';
}
alert("fas");
}
我的代码出了什么问题?当调用detil_iklan(e)时,不会调用alert。任何人都可以帮助我吗?
感谢,
答案 0 :(得分:0)
<强> Added a function to find next sibling
强>
function detil_iklan(e) {
var parent = e.parentNode;
var next = get_nextsibling(parent);
if (next.style.display == 'none') {
next.style.display = '';
} else {
next.style.display = 'none';
}
}
//function to find next sibling
function get_nextsibling(n) {
x = n.nextSibling;
while (x.nodeType != 1) {
x = x.nextSibling;
}
return x;
}