HTML5输入颜色的默认颜色 [英] HTML5 input color's default color
问题描述
input type =color
的默认颜色为黑色:#000000
。
即使我给它一个空值...
< input type = colorvalue =/>
...默认颜色总是黑色。
我想让用户有选择颜色的选择,但如果他不是这意味着没有选择颜色,甚至不是白色 #FFFFFF
。
有没有办法强制输入类型=颜色
不使用黑色作为默认值?
我可以使用某种监听器来检查用户是否首次更改颜色,如果没有,则忽略该值,但我想避免JavaScript。
在 value
c $ c>< input type =color> ,我注意到的一件事是它必须是六位数,如果你使用 #fff
,它不工作。它必须
#ffffff
。
通过javascript设置时也会发生同样的情况。
document.querySelector('input [type =color]')。value ='#fff'
颜色保持黑色。
你必须使用 document.querySelector('input [type =color]')。value ='#ffffff'
p>
需要注意的事情。
The input type="color"
has a default color which is black: #000000
.
Even if I give it an empty value...
<input type="color" value="" />
...the default color is always black.
I want the user to have the option of picking a color, but if he doesn't it means no color was picked, not even white #FFFFFF
.
Is there a way to force an input type="color"
not to have black color as default?
I can use some kind of a "listener" to check if the user changed the color for the first time, if not, ignore the value, but I would like to avoid Javascript.
While using hexcode for value
attribute in <input type="color">
, one thing I noticed is that it has to be six digits, if for white you use #fff
, it does not work. It has to be #ffffff
.
The same thing happens when setting it through javascript.
document.querySelector('input[type="color"]').value = '#fff'
does not work. The color remains black.
You have to use document.querySelector('input[type="color"]').value = '#ffffff'
for it to work.
Something to be careful about.
这篇关于HTML5输入颜色的默认颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!