Jquery Colorpicker 在输入字段中显示值

发布于 2024-12-22 19:16:15 字数 184 浏览 3 评论 0原文

我使用这个颜色选择器插件:http://www.eyecon.ro/colorpicker/

如何在输入字段中显示起始值?

这是我拥有的 JSFiddle: http://jsfiddle.net/z6Ddy/

I use this colorpicker plugin:http://www.eyecon.ro/colorpicker/

How can i show the start value in the inputfield?

Here is a JSFiddle what i have: http://jsfiddle.net/z6Ddy/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小姐丶请自重 2024-12-29 19:16:15

不要使用 attr 设置值

$('#colorSelector input').attr('value', '#' + hex);

而是使用

$('#colorSelector input').val('#' + hex);

Dont use attr to set a value

$('#colorSelector input').attr('value', '#' + hex);

Instead use

$('#colorSelector input').val('#' + hex);
北城半夏 2024-12-29 19:16:15

我假设您会将值存储在数据库中以供稍后使用。如果是这样,您将需要使用您选择的任何脚本语言来填充文本输入、显示颜色的 div 背景以及拾色器初始化的颜色属性。

所以基本上,您将检查数据库中是否设置了值,如果是,则将十六进制值插入 div 样式的背景颜色属性、文本输入的 value 属性以及“颜色”颜色选择器初始化的属性。

如果未设置值,您可以设置默认值,例如“#FF0000”。

我更新了小提琴,添加了注释,您可以通过脚本或ajax插入数据,但您的问题是我认为比 jQuery 和颜色选择器更以 PHP 或 .NET 为中心。

I'm going to assume you'll store the value in a database for use later. If so, you'll want to use whatever scripting language of your choice to populate the text input, the background of the div that shows the color, and the color attribute of the Color Picker initialization.

So basically, you'll check to see if there's a value set in the database, and if so, insert the hex value into the background-color property of the div style, and value attribute of the text input, and the "color" property of the color picker initialization.

If no value is set, you can set a default, say "#FF0000."

I updated the fiddle, adding comments where you would insert data via a script or ajax, but your question is more PHP or .NET centric I think than jQuery and Color-picker.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文