0
<?php

if(isset($_POST['take-attendance'])){
$date = date("d/m");
echo'<center><table><tr><th> Student-Id </th> <th> Name </th> <th>'.$date.'</th></tr>';

foreach($sheet_data as $row) {

    echo '<tr><td>'.$row['id'].'</td><td>'.$row['name'].'</td><td> <input type = "button"  value = "A" name = "'.$row['id'].'" id = "'.$row['id'].'" class = "apbutton" ></td></tr>';

}       
 echo '</table></center>';

} 

?>

<script>

$(".apbutton").live("click", function() {
    var buttonId = $(this).attr("id");
    alert(buttonId);
}); 


</script>

ここで、クラス apbutton nd を使用して入力ボタンを生成しました。ボタン ID を取得しようとしていますが、これが機能していません。どこが間違っているのか教えてください。

4

1 に答える 1

4

コードの準備が整うまで待ちます。(.live非推奨なので、に切り替えました.on

$(function(){

    $(".apbutton").on("click", function() {
        var buttonId = $(this).attr("id");
        alert(buttonId);
    });

});
于 2013-07-14T18:46:06.597 に答える