JQuery jPicker> Assign jPicker color from a text link (not from jPicker)

I have a list of commonly used hex colors that I would like to list under my jPicker related input text box, and I would like to figure out how to change the value of the active jPicker color without opening the jPicker color picker palette.

I managed to create a function that updates the input field associated with jPicker, but the background colors and picker.gif are not updated. I would like to make the background colors update as if the color was selected from jPicker itself.

Here is my code for the activation link ...

<span onclick=doColor(1,'cc9900')>cc9900</span>

And here is the js handler

function doColor(el, color)
 {
 if(el){$('#theme_header_color').attr('value', color);}
 else{$('#theme_sidebar_color').attr('value', color);}
 }
+3
source share
3 answers

Have you tried to trigger the keyup event after changing the value of the input field?

function doColor(el, color) {
    $('#theme_header_color').val(color).trigger('keyup');
}
+2

, jPicker. (V1.1.0) jPicker http://www.digitalmagicpro.com/jPicker/. , .

, Color Color script . , , . Color, .

, HEX, "keyup". "val" .

, Color.

<div id="Picker">&nbsp;</div>
<div id="Favorites">
  <span title="cc9900"/>
  <span title="e2ddcf"/>
  <span title="ffcc00"/>
</div>

$.jPicker('#Picker');
$('#Favorites span').click(
  function()
  {
    $.jPicker.List[0].color.active.val('hex', $(this).attr('title'));
  });

, "title", .

+2

- , , , , . https://files.nyu.edu/mr2723/public/picker.html.

, - click programatically , html "onclick".

$(document).ready(function () {
    $.jPicker('#Picker');
    $('#spanID').click(function () {
        $.jPicker.List[0].color.active.val('hex', color, $(this).attr('color'));
    });
});
+1
source

Source: https://habr.com/ru/post/1737960/


All Articles