Bootstrap Colorpicker,如何在下拉列表中设置颜色值框?

时间:2016-03-21 06:36:52

标签: javascript jquery twitter-bootstrap color-picker

我正在使用Bootstrap Colorpicker 2.3,但我的要求是,我想在颜色选择器like this example中添加文本字段值框,是否可能?请你帮助我,谢谢你。

1 个答案:

答案 0 :(得分:2)

使用其他一些代码更新了您的小提琴。

插件有changeColor个事件。使用它来更新输入元素值。

$('.demo2').on('changeColor.colorpicker', function(a, b, c) {
    $('.store').val($(this).colorpicker('getValue'))
});



$('.demo1').colorpicker();

$('.demo2').colorpicker({
  template: '<div class="colorpicker dropdown-menu">' +
    '<div class="colorpicker-saturation"><i><b></b></i></div>' +
    '<div class="colorpicker-hue"><i></i></div>' +
    '<div class="colorpicker-alpha"><i></i></div>' +
    '<div class="colorpicker-color"><div /></div>' +
    '<div class="colorpicker-selectors"></div>' +
    '<div class="colorpicker-selectors"></div>' +
    '<input type="text" value="" class="store" />' +
    '</div>',
  input: '.store'
});


$('.demo2').on('changeColor.colorpicker', function(a, b, c) {
  $('.store').val($(this).colorpicker('getValue'))
});
&#13;
.demo1,
  .demo2 {
    width: 200px;
    margin: 30px;
  }
&#13;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.12.0/jquery.js" type="text/javascript"></script>
<link href="/css/normalize.css" type="text/css" rel="stylesheet">
<link href="/css/result-light.css" type="text/css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/2.3.0/js/bootstrap-colorpicker.js" type="text/javascript"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/2.3.0/css/bootstrap-colorpicker.min.css" type="text/css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" type="text/css" rel="stylesheet">





<div class="input-group demo1">
  <input type="text" value="" class="form-control" />
  <span class="input-group-addon"><i></i></span>
</div>


<div class="form-group">
  <div class="field-title">With template</div>
  <div class="input-group input-picker demo2">
    <input type="text" value="" class="form-control" />
    <div class="dss"></div>
    <span class="input-group-addon"><i></i></span>
  </div>
</div>
&#13;
&#13;
&#13;

Fiddle