admin管理员组

文章数量:1313333

I'm having difficulty with jscolor, or / I would like to change the value of the color in javscript, not just be able to type it in or pick it with clicking. I've looked into its code and found where it updates, but I can't figure out a way to rerun the function whenever I change the value.

document.getElementById('idTryingToChange').value

This is essentially where I'm able to obtain the information of the color that is selected, but if I write a string to it for example it will only write the text not change the background-color function or basically update the js color, like it would if I typed in the color. I realized it must be on a keyup or keydown event and found a function that is in the js color script. Now I just need to find a way to run the function or is that not going to work? By the way the function is:

var updateField = function() {
            THIS.fromString(valueElement.value, leaveValue);
            dispatchImmediateChange();
        };

So if you're looking through the jscolor code it will be easier to find with this info or look up keyup in the script. Thanks for any help. If the question seems to vague or you need more details let me know. I know it seems kind of like a weird bug. Also I found something about binding to ids in the code on the js color website, but that didn't seem to work.

I'm having difficulty with jscolor, or http://jscolor./ I would like to change the value of the color in javscript, not just be able to type it in or pick it with clicking. I've looked into its code and found where it updates, but I can't figure out a way to rerun the function whenever I change the value.

document.getElementById('idTryingToChange').value

This is essentially where I'm able to obtain the information of the color that is selected, but if I write a string to it for example it will only write the text not change the background-color function or basically update the js color, like it would if I typed in the color. I realized it must be on a keyup or keydown event and found a function that is in the js color script. Now I just need to find a way to run the function or is that not going to work? By the way the function is:

var updateField = function() {
            THIS.fromString(valueElement.value, leaveValue);
            dispatchImmediateChange();
        };

So if you're looking through the jscolor code it will be easier to find with this info or look up keyup in the script. Thanks for any help. If the question seems to vague or you need more details let me know. I know it seems kind of like a weird bug. Also I found something about binding to ids in the code on the js color website, but that didn't seem to work.

Share Improve this question asked Feb 24, 2015 at 1:50 Nicholas KalscheuerNicholas Kalscheuer 6636 silver badges14 bronze badges 1
  • This is a link to the demo the color picker so you know what I'm talking about a little more: jscolor./try.php – Nicholas Kalscheuer Commented Feb 24, 2015 at 1:51
Add a ment  | 

3 Answers 3

Reset to default 6

I was looking for how to do this the other day and I ended up using this

document.getElementById('idToChange').jscolor.fromString(jsObj.toHEXString());

This worked much better for me since it changes the color of the text according to the background color. I found it in the setting colors example.

If you update the input's contents with JS and want to update the background color, you can use something like this:

$('.jscolorinput').each(function()
{
    $(this)[0].color.fromString($(this).val());
}); 

This piece of code snippet will update any references to your colour pickers assuming they have the class '.jscolorinput'. You can use any selectors to find the pickers, such as IDs, CSS classes, etc.

But for instances, you can try this:

jsInstanceObj.fromString('#BCFFE6FF');

It will trigger the change event automatically.

本文标签: javascriptHow to change the value of JsColor and run jscolor39s functionsStack Overflow