HTML5 input color's default color

前端 未结 7 2104
感情败类
感情败类 2021-02-01 01:16

The input type=\"color\" has a default color which is black: #000000.

Even if I give it an empty value...

7条回答
  •  温柔的废话
    2021-02-01 01:46

    Don't know if this issue is only available on chrome, but I just found the quick fix for chrome. We need to set the input value to #FFFFFF first and after that set it to default value, the default color will appear instead of black

    var element = document.querySelector('input[type="color"]');
    element.value = '#FFFFFF'; //remember the hex value must has 7 characters
    element.value = element.defaultValue;
    

    Hope it help someone :)

提交回复
热议问题