如何根据 jquery 输入的值更改输入字段的背景颜色
How to change the background-color of an input field based on the val of that input with jquery
我有一个带有十六进制颜色值的输入字段:
<input class="color" value="#ff0000" /> // ff0000 is red
我如何从该字段中读取 val 并将该值设置为该字段的背景颜色?
所以我想实现:
<input class="color" style="background-color: #ff0000;" value="#ff0000" />
一点帮助:
$(document).ready(function(){
var bgcolor = $('.color').val(); // create var which reads the value from input with class .color
$('.color').css( "background-color", bgcolor ); // now set css rule to the same .color class with that var
});
我有一个带有十六进制颜色值的输入字段:
<input class="color" value="#ff0000" /> // ff0000 is red
我如何从该字段中读取 val 并将该值设置为该字段的背景颜色? 所以我想实现:
<input class="color" style="background-color: #ff0000;" value="#ff0000" />
一点帮助:
$(document).ready(function(){
var bgcolor = $('.color').val(); // create var which reads the value from input with class .color
$('.color').css( "background-color", bgcolor ); // now set css rule to the same .color class with that var
});