Javascript 单击复选框后立即在动态表的警报框中显示行id
我在stackoverflow中对此进行了大量研究,但没有一个解决方案适合我Javascript 单击复选框后立即在动态表的警报框中显示行id,javascript,html,tablerow,Javascript,Html,Tablerow,我在stackoverflow中对此进行了大量研究,但没有一个解决方案适合我 <div class="ibox-content"> <div class="table-responsive"> <table class="table table-striped table-bordered table-hover dataTables-example tdiv"
<div class="ibox-content">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover dataTables-example tdiv" id="resultTable" >
<thead>
<tr>
<th></th>
<th>Company Name</th>
<th>Niche</th>
<th>Date Added</th>
</tr>
</thead>
<tbody>
@foreach($companies as $company)
<tr class="clickable-row" id="{{$company->id}}">
<td align="center"><input type="checkbox" class="i-checks" name="input[]"></td>
<td>{{ $company->name }}</td>
<td>{{ $company->niche }}</td>
<td>{!! date('M j, Y', strtotime($company->created_at)) !!}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
公司名称
市场定位
添加日期
@foreach($公司作为$公司)
{{$company->name}
{{$company->niche}
{!!date('mj,Y',strottime($company->created_at))
@endforeach
我的Javascript是:
<script type="text/javascript">
$("#resultTable").click(function(){
var closestTr = $(':checkbox:checked').closest('tr').attr('id');
alert(closestTr);
});
</script>
$(“#可结果”)。单击(函数(){
var closestTr=$(':复选框:checked')。最近('tr')。attr('id');
警报(关闭sttr);
});
这是因为我用的是ibox还是别的什么?我不知道发生了什么请帮忙。答案很简单 我所需要做的就是将Javascript更改为复选框的类 像这样:
$(document).ready(function() {
$('.i-checks').click(function(event) {
var companyId = this.id;
console.log(companyId);
alert(companyId);
});
});