1

I am working in jQuery Color Picker. I am having a constant data in my web.config file.

<add key="colorCode" value="8A2BE2,0000FF,A52A2A,D87093,00FFFF,FFE4C4,008080,FF00FF,B8860B,FF8C00,800080,DA70D6,40E0D0"/>

I my aspx page, i am having the method like

 var colorCode = '<%=ConfigurationManager.AppSettings["colorCode"]%>';
 $(function () {
 $('#color3').colorPicker({ pickerDefault: "ffffff", colors: [colorCode], transparency: true });
 });

The color picker is not recognising the colors which i had given in the web config file. How to fix this.

4

1 回答 1

3

I think your problem is that you are passing the values like:

["000, 000, fff, fff"];

and you need

['000', '000', 'fff', 'fff'];

as showed here.

Try adding the '' in the config, or using split

"000, 000, fff, fff".split(","); //["000", " 000", " fff", " fff"]

In your code, the options look like this:

1

Config

 <add key="colorCode" value="8A2BE2,0000FF,A52A2A,D87093,00FFFF,FFE4C4,008080,FF00FF,B8860B,FF8C00,800080,DA70D6,40E0D0"/>

Code

var colorCode = '<%=ConfigurationManager.AppSettings["colorCode"]%>';
 $(function () {
      $('#color3').colorPicker({ 
             pickerDefault: "ffffff", 
             colors: colorCode.split(","), 
             transparency: true 
      });
 });

2

Config

 <add key="colorCode" value="'8A2BE2','0000FF','A52A2A','D87093','00FFFF','FFE4C4','008080','FF00FF','B8860B','FF8C00','800080','DA70D6','40E0D0'"/>

Code

var colorCode = [<%=ConfigurationManager.AppSettings["colorCode"]%>];
 $(function () {
      $('#color3').colorPicker({ 
             pickerDefault: "ffffff", 
             colors: colorCode, 
             transparency: true 
      });
 });

If neither of them work, try removing the ' ' in the 1 example, when getting the value from the config

于 2012-08-14T14:23:19.883 回答