如何获得类型=“颜色"的值?使用javascript输入 [英] how to get value of type="color" input using javascript
本文介绍了如何获得类型=“颜色"的值?使用javascript输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在项目中使用了上面的html代码..但我不知道如何使用javascript获取上述输入的价值
I used this above html code for my project..but i don't know how to get value of above input using javascript
<form>
<input type="color" id="favcolor">
</form>
有人可以帮助我吗?
谢谢
推荐答案
简单地获取值
document.getElementById("favcolor").value;
如果要在选择更改时获得颜色,则可以添加事件侦听器.你会做这样的事情
You can add an event listener if you want to get the color when the selection changes. You'd do something like this
var theInput = document.getElementById("favcolor");
var theColor = theInput.value;
theInput.addEventListener("input", function() {
<<Do something with theColor value here>>
}, false);
这是一个工作示例: http://jsfiddle.net/3fehj/
这篇关于如何获得类型=“颜色"的值?使用javascript输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文