相关文章推荐
咆哮的牛肉面  ·  SignalR Hub 在 .NET ...·  1 月前    · 
孤独的钢笔  ·  jQuery ...·  1 月前    · 
还单身的松球  ·  jquery ...·  1 月前    · 
完美的抽屉  ·  jquery ...·  1 月前    · 
从容的鼠标  ·  Recover (Spring Retry ...·  1 年前    · 
坚强的伤痕  ·  ORA-01830: ...·  2 年前    · 
奔跑的西瓜  ·  HMAC-SHA-256 in PHP - ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

i have a simple text field which has a colorpicker attached to it. i have added an icon next to the field, which is able to remove the content of the field value (which was generated by the color picker). code is below.

the strange thing is that after i delete the value - if i click elsewhere on the page, the value comes back! code and simple sample below.

reproduction steps:

  • generate hex code by using the colorpicker.
  • click on the X to delete the field value.
  • click elsewhere in the page body, the value will return.
  • many thanks

    HTML code:

      <input type="text" name="x_fontColor" id="x_fontColor" size="30" maxlength="10" value="" class="colorpicker">
      <span class="trigger" data-for="x_fontColor">X </span>
    
    $(".colorpicker").colorpicker();            
    $(".trigger").click(function(){
       $("#"+$(this).data('for')).val('');              
    

    FIDDLE LINK: http://jsfiddle.net/W2Mcy/

    It happens in the plugin's site too.They are using mousedown event in their calculations here. – anpsmn Jul 16, 2013 at 20:05

    I tried it in your fiddle, and it is working but the below sets the #ff0000 as default color.

    $(".trigger").on('click', function(){
                    $('input').colorpicker('setValue', '').val(''); // clear both value of input and set default color  
    

    See this updated fiddle.

    Hope you understand.

    I know this is an old thread, but if someone else runs into this issue you can assign 'transparent' as the value.

    .colorpicker('setValue','transparent');
    

    Unfortunately the color picker will display 'transparent' in the field so it's not entirely a null or '' value, but it's close and it should work if you're doing a live update of the color in a preview type of situation.

    Hope this helps.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.