我希望获取单击元素的、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;
}
发布于 2016-12-21 05:55:36
似乎你需要委派这个事件
$('body').on('click','.sems',function(event) {
var _id = $(this).attr('id');
alert(_id);
})
https://stackoverflow.com/questions/41255984
复制相似问题