默认情况下,如果我们选择它显示的一种颜色是输入框中的颜色代码,如果我们选择接下来它会覆盖最后选择的颜色值。但我想用逗号分隔符附加所有选定的颜色值。喜欢这个#7623131,#252525,#369855。我很困惑我是否必须覆盖插件函数或者必须编写任何其他用户定义的函数。
{{1}}
答案 0 :(得分:1)
input
活动Array#join
将items
与delimeter
Array#indexOf
检查array
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'/>