如何在频谱js输入框中附加多个颜色值?

时间:2016-09-26 11:40:14

标签: javascript jquery jquery-plugins

enter image description here

默认情况下,如果我们选择它显示的一种颜色是输入框中的颜色代码,如果我们选择接下来它会覆盖最后选择的颜色值。但我想用逗号分隔符附加所有选定的颜色值。喜欢这个#7623131,#252525,#369855。我很困惑我是否必须覆盖插件函数或者必须编写任何其他用户定义的函数。

{{1}}

2 个答案:

答案 0 :(得分:1)

var arr = [];
$('[type="color"]').on('input', function() {
  if (this.value && arr.indexOf(this.value) === -1) {
    arr.push(this.value);
    $('[type="text"]').val(arr.join(', '));
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="color">
<input type="text">

答案 1 :(得分:0)

$(()=>{
  $('#Color').on('change', function() { 
     $('#txtColor').val( $('#txtColor').val()+','+ $('#Color').val());
  });
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='color' id='Color' />
<input type='text'  id='txtColor'/>

相关问题