Мне нужно выделить всю строку, используя jquery или php. Есть какой-либо способ сделать это? или, пожалуйста, предложите мне альтернативу?
Вот код, над которым я работаю:
<table id ="gdRows" class="table table-bordered">
<tr class="info">
<td><input type='checkbox' id="selectall" onclick = "selectAll(this)"></td>
<td><strong>Username</strong></td>
<td><strong>Password</strong></td>
</tr>
<?php
for($i=0; $row = $qry->fetch(); $i++){
$username = $row['username'];
$password = $row['password'];
?>
<tr class="success">
<td><input type="checkbox" name="chkDelete" ></td>
<td><?php echo $username; ?></td>
<td><?php echo $password; ?></td>
</tr>
<?php
}
?>
</table>
Вы можете сделать это с помощью этого jQuery и класса CSS:
$('input[name="chkDelete"]').click(function () {
$(this).closest('tr').removeClass('foo');
if ($(this).is(':checked')) $(this).closest('tr').addClass('foo');
})
// jQuery
$('tr').find('input').on('click', function() {
if ($(this).prop('checked') === true) {
$(this).closest('tr').addClass('highlighted');
} else {
$(this).closest('tr').removeClass('highlighted');
}
});
// CSS
.highlighted td {
background: yellow;
}
Здесь скрипка
Попробуй это,
<script src="jquery.js"></script>
<script type="text/javascript">
$(function(){
$(".Row").click(function(){
if($(this).is(":checked")){
$(this).closest('tr').css({backgroundColor: 'red'});
}else{
$(this).closest('tr').css({backgroundColor: ''});
}
});
});
</script>
HTML:
<tr class="success">
<td><input type="checkbox" name="chkDelete" class="Row"></td>
<td><?php echo $username; ?></td>
<td><?php echo $password; ?></td>
</tr>
Вы должны использовать jquery для выделения строки, указанной на jquery-10.1.2
$(function () {
$('#selectall').on('click',function(){
$('yourdivwhichyouwanttohighilit').css('background-color','red');
})
});