问题描述
我正在使用jPicker插件从选择器中获取颜色.我以这种方式创建元素:
I'm using jPicker plugin to get a color from a picker. I create the element in this way:
$(function(){
$('#txtBackgroundColor').jPicker(
{
color:
{
mode: 'h', // acceptable values "h" (hue), "s" (saturation), "v" (brightness), "r" (red), "g" (green), "b" (blue), "a" (alpha)
active: new $.jPicker.Color({ hex: 'eaeaea' }), // accepts any declared jPicker.Color object or hex string WITH OR WITHOUT '#'
},
window:
{
position:
{
x: 'screenCenter', // acceptable values "left", "center", "right", "screenCenter", or relative px value
y: '200px', // acceptable values "top", "bottom", "center", or relative px value
},
expandable: true
},
},
});
当我单击一个按钮时,我想设置该jpicker的活动颜色.我在文档中看到以下这一行:
When I click a button I want to set the active color of that jpicker. I have seen in the documentation this line:
$('#update').click(function(){
$.jPicker.List[0].color.active.val('hex', 'e2ddcf', this);
});
但是问题是我有多个jPicker,例如,我不知道List的索引,有没有一种方法可以通过id而不是通过索引List来设置jPicker颜色?
But the problem is that I have multiple jPicker, and I don't know the index of the List for example, is there a way to set the jPicker color by id and not by index List?
谢谢
推荐答案
设置值
var control= $('#txtBackgroundColor')
var colorPicked = '#e2ddcf';
control.jPicker({
color: { active: colorPicked}
});
control[0].color.active.val('hex', colorPicked);
control.val(colorPicked.replace("#", ""));
根据您的情况,上面的某些行可能无关紧要.
Dependent on your scenario some of the lines above may be irrelevant.
查找ID ,如果:
$('#txtBackgroundColor')
像这样用jPicker类查找跨度是不正确的
is incorrect look for the span with jPicker class on it like this
<span class="jPicker">
在此之上,应该有一个显示样式为没有的带有ID值的输入.在上面的示例中使用那个.
Just above that, there should be an input with a display style of none with an ID value. Use that one in the above example.
这篇关于jPicker设置颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!