나는 내 테이블의 첫 번째 TR 만 가져 오려고합니다. 각 행의 삭제 버튼을 클릭하면 어쨌든 작동합니다. 나는 그것을 얻을 수 없다! 제출 후 맨 처음 행을 삭제하고 싶습니다 ... 첫 번째 행을 제외하고 모두 작동합니다! 난 ... 분명 해요 경우 몰라 ... 그들을 제거하기 위해 myTable에의 행에 대한 ID를 태그에 대한 내 SQL에서 동일한 ID를 사용첫 번째 테이블 행 찾기
<table id ="myTable" border="0" cellpadding="0" cellspacing="0" width="100%" class="scrollTable1">
<thead class="fixedHeader1">
<tr>
<th><center><a href="#">Id</a></center></th>
<th><center><a href="#">User</a></center></th>
<th><center><a href="#">Dest</a></center></th>
<th><center><a href="#">Msg</a></center></th>
<th><center><a href="#">Title</a></center></th>
<th><center><a href="#">Date</a></center></th>
<th><center><a href="#">Hour</a></center></th>
<th><center><a href="#">Langue</a></center></th>
<th><center><a href="#">Del</a></center></th>
</tr>
</thead>
<tbody class="scrollContent1">
<?
$sql="SELECT * FROM messages ORDER BY username";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo'<tr id="'.$row[messageid].'">
<td><center>'.$row[messageid].'</center></td>
<td><center>'.addslashes(utf8_decode($row[username])).'</center></td>
<td><center>'.addslashes(utf8_decode($row[dest])).'</center></td>
<td><center>'.utf8_decode($row[message]).'</center></td>
<td><center>'.$row[titre].'</center></td>
<td><center>'.$row[date].'</center></td>
<td><center>'.$row[heure].'</center></td>
<td><center>'.$row[langue].'</center></td>
<form name="ajaxform" id="ajaxform" action="delete_msg_SQL.php" method="POST">
<td><center><input type="button" class= "myButton" id="'.$row[messageid].'" value="X"/><input type="button" style="visibility:hidden" id="simple-post"/></center></td>
</form>
</tr>';
}
?>
</tbody>
</table>
JQuery와 코드 :
<script>
$(function(){
$('.myButton').click(function() {
var myId = $(this).attr('id');
$("#ajaxform").append('<input type="hidden" name="id" value="'+ myId + '"/>');
// HERE the PROBLEM If I click on the delete button on each rows it works anyway instead of the first one!
if ($(this).children('tr:first')) {
alert('ok');
}
$('#simple-post').click();
$('#'+ myId).remove();
});
});
</script>
하지 정말 선택을 시도하십시오 수행하는 ... 버튼을 클릭하고'if ($ (this) .children ('tr : first'))'? 그게 작동하지 않을 것입니다, 버튼은 테이블 행인 자식을 가지지 않을 것입니다. – Joeytje50
네가 완벽하게 맞았다! 큰 실수 ! 하지만이 버튼이 첫 번째 행에서 클릭되면 거기에서 갈 수 있습니까? – user3281883
질문이 매우 모호하며 어쨌든 렌더링 된 HTML이 유효하지 않으며 ID가 문서 컨텍스트에서 고유해야합니다. 왜 각 행에 ID를 사용합니까? –