Data table multiple row selection
How to change background color of row when I 开发者_JAVA百科click the checkbox?
You need a shot of Javascript for this.
<h:selectBooleanCheckbox onclick="highlightRow(this)">
with
function highlightRow(checkbox) {
getParentByTagName(checkbox, 'tr').style.background = (checkbox.checked) ? '#6f6' : 'none';
}
function getParentByTagName(element, tagName) {
var p = element.parentNode;
return p ? ((p.tagName.toLowerCase() == tagName.toLowerCase()) ? p : getParentByTagName(p, tagName)) : false;
}
Or if you're already using jQuery:
function highlightRow(checkbox) {
$(checkbox).closest('tr').css('background', checkbox.checked ? '#6f6' : 'none');
}
精彩评论