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
3 Answers
Reset to default 6I 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
版权声明:本文标题:javascript - How to change the value of JsColor and run jscolor's functions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741926178a2405300.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论