javascript 光谱颜色选择器获取颜色的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19324524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spectrum color picker get the value of the color
提问by mengmeng
I implemented Spectrum's color picker just fine
我很好地实现了 Spectrum 的颜色选择器
$(document).ready(function() {
$("#font_color").spectrum({
color: "#f00"
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/bgrins/spectrum/master/spectrum.js"></script>
<link href="https://cdn.rawgit.com/bgrins/spectrum/master/spectrum.css" rel="stylesheet"/>
<input type="text" id="font_color" />
But I don't know how to get the value inside the texfield using javascript. Can someone help me?
但我不知道如何使用 javascript 获取 texfield 中的值。有人能帮我吗?
采纳答案by Dvir
the value of the input?
输入的值?
var value = $("#font_color").val();
回答by Bob Tate
Another way to also get it, if the input field method does not work for you, is directly from spectrum itself.
如果输入字段方法不适合您,另一种获取它的方法是直接从频谱本身获取。
$("#font_color").spectrum('get');
or
或者
$("#font_color").spectrum('get').toHexString();
To get it converted.
让它转换。
回答by user2888692
Use color.toRgbString() work for me
使用 color.toRgbString() 对我来说有效