开发者

change color value with colorpicker

开发者 https://www.devze.com 2023-03-01 07:42 出处:网络
How do I change the bgcolor of \'colorId\'. I tried the code below and I want the bgcolor to change in the value \'val\'. But from then开发者_运维问答 on I m doing something wrong.

How do I change the bgcolor of 'colorId'. I tried the code below and I want the bgcolor to change in the value 'val'. But from then开发者_运维问答 on I m doing something wrong.

 <script type="text/javascript">

        function updatevariable(elm) {

            val = elm;
            var divElement = document.getElementById(colorId);
            divElement.bgcolor = val;
        }
    </script>


<table width="150" border="0" cellspacing="1" cellpading="0" align="center">
<tr>
<td bgcolor="#190707" onclick="updatevariable(this.bgColor)">&nbsp;</td>
<td bgcolor="#fa5858" onclick="updatevariable(this.bgColor)">&nbsp;</td>
<td bgcolor="#F4FA58" onclick="updatevariable(this.bgColor)">&nbsp;</td>
<td bgcolor="#00FF00" onclick="updatevariable(this.bgColor)">&nbsp;</td>
<td bgcolor="#fbefef" onclick="updatevariable(this.bgColor)">&nbsp;</td>
</tr>
<tr>
<td id='colorId' bgcolor="#F4FA58">&nbsp;</td>
</tr>
</table>


If you switch to jQuery you can do this in stead:

function updatevariable(elm){
  var val = elm;
  $('#colorId').css('background-color', val);
}

Just found your bugs. Use code below and it would work.

function updatevariable(elm) {
     var val = elm;
     var divElement = document.getElementById("colorId");
     divElement.setAttribute("bgcolor", val);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消