[英]Changing a Table Row's colour onload
So I'm working on a webpage where an admin can disable and enable users. 因此,我正在研究一个可以禁用和启用用户的网页。 I have it so when the admin disables or enables a user, the text in the user's table row will change colour accordingly.
我有它,所以当管理员禁用或启用用户时,用户表行中的文本将相应地更改颜色。 However, I can't seem to change the row's colour onload.
但是,我似乎无法更改行的颜色加载。 So they all show up as the enabled colour (Black).
因此它们都显示为启用的颜色(黑色)。 Here's my code so far;
到目前为止,这是我的代码;
function loadRow(){
var check_array = document.getElementsByName("checkbox[]");
var array_size = check_array.length;
for(var i =0; i < array_size; i++){
if(check_array[i].checked){
var rowId = check_array[i].value;
document.getElementById(rowId).style.color = "#4D4A49";
}
}
}
My rows are all populated through a PHP connection to my database, and here's the code for that; 我的行都是通过与数据库的PHP连接填充的,下面是代码。
while($row = mysqli_fetch_array($result)){
$output .= '<tr id="row'. $row['id'] .'"><td>' . $row['name'] .'</td>
<td>'. $row['username'] .'</td>
<td>' . $row['email'] . '</td>
<td><input name="checkbox[]" type="checkbox" id="checkbox'. $row['id'] .'" value="' . $row['id'] . '" onchange="disableUser(this.value)" ' . ($row['disable'] == 0 ? 'checked' : '') .'/></td>
<td><a href="deleteUser.php">Delete</a></td>
</tr>';
}
The HTML then looks like this; HTML看起来像这样;
<table border="1">
<tr><th>Name</th><th>Username</th><th>Email</th><th>Disabled</th><th>Delete</th></tr>
<?php echo $output; ?>
</table>
I am wondering if the onload is in the wrong place or not. 我想知道加载是否在错误的位置。 Any suggestions?
有什么建议么? If I left something out, and am unclear, please let me know and I'll edit my post.
如果我遗漏了一些东西,并且不清楚,请让我知道,我将编辑我的帖子。 Thanks.
谢谢。
You have used: 您已使用:
'<tr id="row'. $row['id'] .'">'
but 但
var rowId = check_array[i].value;
document.getElementById(rowId).style.color = "#4D4A49";
is using the value attribute from the checkboxes which are set to: 正在使用复选框中的value属性,这些属性设置为:
value="' . $row['id'] . '"
hence either change: 因此,要么更改:
document.getElementById('row' + rowId).style.color = "#4D4A49";
or 要么
'<input name="checkbox[]" type="checkbox" id="checkbox'. $row['id'] .'" value="row' . $row['id'] . '" onchange="disableUser(this.value)" ' . ($row['disable'] == 0 ? 'checked' : '') .'/>'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.