我想要点击元素的 GET ID
或class
。谁能让我知道如何做到这一点?我试图获取点击元素的ID
,但它不起作用。
这是我的jquery。
$('.sems').click(function() {
var id = $(this).attr('id');
alert(id);
});
这里是链接所在的完整代码。
if(isset($_POST['loadsem'])) {
$stud = $_POST['stud'];
$output = '';
$sql = "SELECT DISTINCT sch_year,semester FROM grades WHERE stud_no ='$stud'";
$result = mysqli_query($con,$sql);
$output .= '
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<th>Semesters Attended</th>
</tr>';
while($row = mysqli_fetch_array($result))
{
$sem = $row['semester'];
$year = $row['sch_year'];
$output .= '<tr>
<td><a href="#" class="sems" id="asd">'; <--- Here's the link
if($sem == "1"){
$output .= $row['semester']. "st Semester S.Y " .$row['sch_year'];
} else {
$output .= $row['semester']. "nd Semester S.Y " .$row['sch_year'];
}
$output .='</a></td>
</tr>';
}
$output .= '</table>
</div>';
echo $output;
}
答案 0 :(得分:3)
似乎你需要委派活动
$('body').on('click','.sems',function(event) {
var _id = $(this).attr('id');
alert(_id);
})
答案 1 :(得分:0)