Php 如何将CSS属性值更改为元素的值?
我有以下标记:Php 如何将CSS属性值更改为元素的值?,php,jquery,css,background-color,Php,Jquery,Css,Background Color,我有以下标记: <tr> <th>Colorcode:</th> <td class="get-color-1"><?php echo $debtor['CustomFields'['kleurcode1'];?> <div class="custom-kleurcode1" style="width:40px; height:40px;></div> </td> </tr&
<tr>
<th>Colorcode:</th>
<td class="get-color-1"><?php echo $debtor['CustomFields'['kleurcode1'];?>
<div class="custom-kleurcode1" style="width:40px; height:40px;></div>
</td>
</tr>
<script type="text/javascript">
$(document).ready(function(){
$(".custom-kleurcode1").css("background-color","yellow");
});
</script>
色码:
将值放入DOM中的文本节点时,您可以使用this.previousSibling.textContent
从.custom-kleurcode1
元素的范围检索其值。您可以为css()
提供一个函数,该函数读取并返回要设置的值,如下所示:
$(文档).ready(函数(){
$(.custom-kleurcode1”).css(“背景色”,函数(){
返回this.previousSibling.textContent;
});
});代码>
色码:
#CC0000
您可以将颜色放置在td的单独属性中,例如:
<td class="get-color-1" data-attr-color="<?php echo $debtor['CustomFields'['kleurcode1'];?>">
并更改背景颜色:
$(".custom-kleurcode1").css("background-color", colorCode);
为什么jquery为什么不使用内联样式并通过phpoh设置颜色我没有看到:-/对不起,我的bad@NullPoi没问题:)
$(".custom-kleurcode1").css("background-color", colorCode);