失敗 - 點選一列時,將前方的checkbox選取
by wales
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<table id="tableJobs" class="table table-bordered table-hover tablesorter table-responsive">
<thead>
<tr>
<th>#</th>
<th>Job Name</th>
<th>Source</th>
<th>Destination</th>
<th>Schedule</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr class="success">
<td>
<input type="checkbox" checked="checked" />
</td>
<td>Task1</td>
<td>MP3</td>
<td>172.17.20.116/mp3</td>
<td>00:00 - hourly</td>
<td>Finished</td>
<td>
<button type="button" id="create" class="btn btn btn-success" data-toggle="tooltip" data-placement="bottom" title="Start Job"><span class="fa fa-play"></span>
</button>
<button type="button" id="create" class="btn btn btn-danger" data-toggle="tooltip" data-placement="bottom" title="Disable Schedule"><span class="fa fa-minus-circle"></span>
</button>
</td>
</tr>
<tr>
<td>
<input type="checkbox" />
</td>
<td>Task2</td>
<td>Movies</td>
<td>172.17.20.116/movies</td>
<td>12:00 - weekly:Monday</td>
<td>Running 50%</td>
<td>
<button type="button" id="create" class="btn btn btn-success" data-toggle="tooltip" data-placement="bottom" title="Stop Job"><span class="fa fa-stop"></span>
</button>
<button type="button" id="create" class="btn btn btn-danger disable" data-toggle="tooltip" data-placement="bottom" title="Disable Schedule"><span class="fa...
JavaScript
$("#tableJobs tbody tr").on('click', function () {
var checkbox = $(this).find('input:checkbox');
console.log($(this).find('input:checkbox').attr('checked'));
if ($(this).find('input:checkbox').attr('checked')==="checked") {
checkbox.removeAttr('checked');
} else {
checkbox.attr('checked', 'checked');
}
})