为什么使用“红色”

var inputButtonColor = $('input#button-color');

inputButtonColor.change(function() {
  var inputButtonColorValue = inputButtonColor.val();
  alert(inputButtonColorValue);
  $('input.write-review').css({"background-color": "red" });
});


​http://jsfiddle.net/f4ngg/2/

而且这不与“ inputButtonColor.val()”一起使用

var inputButtonColor = $('input#button-color');

inputButtonColor.change(function() {
  var inputButtonColorValue = inputButtonColor.val();
  alert(inputButtonColorValue);
  $('input.write-review').css({"background-color": inputButtonColorValue });
});


http://jsfiddle.net/f4ngg/1/

最佳答案

您将颜色代码作为文本框的输入,如果要将其更改为颜色,则必须在颜色代码之前添加#

所以代码将是:

var inputButtonColor = $('input#button-color');

inputButtonColor.change(function() {
  var inputButtonColorValue = inputButtonColor.val();
  alert(inputButtonColorValue);
  $('input.write-review').css({"background-color": "#" + inputButtonColor.val() });
});


DEMO

关于jquery - 输入更改时更改CSS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12217729/

10-11 05:54