【发布时间】:2012-11-30 16:43:18
【问题描述】:
我想用jpicker修改多个元素,这是单个元素的代码(#body02),是否可以为每个元素创建一个数组?
$(document).ready(
function()
{
var LiveCallbackElement = $('#body02'),
LiveCallbackButton = $('#LiveButton'); // you don't want it searching this
// on every live callback!!!
$('#Callbacks').jPicker(
{window:{position:{x:'screenCenter',y:'200'}}},
function(color, context)
{
var all = color.val('all');
alert('Color chosen - hex: ' + (all && '#' + all.hex || 'none') +
' - alpha: ' + (all && all.a + '%' || 'none'));
$('#body02').css(
{
backgroundColor: all && '#' + all.hex || 'transparent'
}); // prevent IE from throwing exception if hex is empty
},
function(color, context)
{
if (context == LiveCallbackButton.get(0)) alert('Color set from button');
var hex = color.val('hex');
LiveCallbackElement.css(
{
backgroundColor: hex && '#' + hex || 'transparent'
}); // prevent IE from throwing exception if hex is empty
},
function(color, context)
{
alert('"Cancel" Button Clicked');
});
$('#LiveButton').click(
function()
{
$.jPicker.List[0].color.active.val('hex', 'e2ddcf', this);
});
});
谢谢
【问题讨论】:
-
不清楚你想做什么,(a)单个选择改变几个元素的 bg-color 或(b)几个元素中的每一个都可以单独选择颜色?
标签: jquery color-picker jquery-callback jpicker