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 的输入按钮,我正在尝试获取按钮 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 回答