Jquery函数不适用于php回显代码

Jquery函数不适用于php回显代码,php,jquery,Php,Jquery,我是php新手。 我想使用jquery从php回显代码中删除一个表行,但它不起作用。 以下是我的html代码: <!DOCTYPE html> <html> <head> <title>test insert</title> <script src="jquery-2.0.3.js"></script> <script type="text/javascript"> $(document).read

我是php新手。
我想使用jquery从php回显代码中删除一个表行,但它不起作用。 以下是我的html代码:

<!DOCTYPE html>
<html>
<head>
<title>test insert</title>
<script src="jquery-2.0.3.js"></script> 
<script type="text/javascript">
$(document).ready(function(){
    $('.del').click(function(){
        $(this).parent().parent().fadeOut('slow');
    });

    $('#show').click(function(){
        $.post('data.php',{action: "show"},function(res){       
            $('#result').hide().html(res).fadeIn('slow');   
        });     
    });
});
</script>
</head>
<body>
   <h2>Show Data</h2>
   <button id="show">Show</button>
   <p>Result:</p>
   <div id="result"></div><br>
</body>
</html>

测试插入
$(文档).ready(函数(){
$('.del')。单击(函数(){
$(this.parent().parent().fadeOut('slow');
});
$(“#显示”)。单击(函数(){
$.post('data.php',{action:'show},函数(res){
$('#result').hide().html(res.fadeIn('slow');
});     
});
});
显示数据
显示
结果:


下面是我的php代码:

<?php
//connect to db
$con = mysql_connect('localhost','root');
$db = mysql_select_db('test');
//if show key is pressed show records
if($_POST['action'] == 'show'){
    $sql   = "select * from customer order by Firstname";
    $query = mysql_query($sql);

    echo "<table><tr><th>Firstname</th><th>Lastname</th><th>Keynumber</th>
    <th>Number2</th><th>Number3</th><th>Option</th><th><button class='del' >delete</button></th></tr>";
    while($row = mysql_fetch_array($query)){
        echo "<tr><td>$row[firstname]</td><td>$row[lastname]</td><td class='key'>$row[keynumber]</td>
        <td>$row[number2]</td><td>$row[number3]</td><td><button class='del' >delete</button></td></tr>";
    }
    echo "</table>";
}
?>

单击“显示”按钮时,您的数据看起来是动态加载的。如果是这样,则需要使用
.on()
而不是
。单击()
,然后单击.on()。将删除按钮代码更改为:

$(document).on('click', '.del', function(){
    $(this).parent().parent().fadeOut('slow');
});

我已经更正了你的代码,检查一下

<script type="text/javascript">
$(document).ready(function(){
    $('.del').click(function(){
        $(this).parent().parent().fadeOut('slow');
    });

    $('#show').click(function(){
        $.post(
         url:'data.php',
         data:{action: "show"},
         type:'POST',
         function(res){       
            $('#result').hide().html(res).fadeIn('slow');   
        });     
    });
});

</script>

$(文档).ready(函数(){
$('.del')。单击(函数(){
$(this.parent().parent().fadeOut('slow');
});
$(“#显示”)。单击(函数(){
美元邮政(
url:'data.php',
数据:{操作:“显示”},
类型:'POST',
函数(res){
$('#result').hide().html(res.fadeIn('slow');
});     
});
});

+1,但在这种情况下,上升到
$(“#结果”)可能就足够了。