【问题标题】:how to code a on click event function for automatically generated button如何为自动生成的按钮编写点击事件函数
【发布时间】:2013-07-14 18:43:51
【问题描述】:
<?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 但这不起作用,请告诉我我错在哪里

【问题讨论】:

    标签: php jquery button input onclick


    【解决方案1】:

    等待代码准备好。 (由于不推荐使用.live,我切换到.on

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

    【讨论】:

    • @user2492144 快乐
    猜你喜欢
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-03
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多