[英]HTML5 input type Colour , how to change its value using javascript
the in the image you can see pencil and eraser buttons, what i want is when pencil is clicked the value of the input should be changed to black, and when its eraser it should be white. 在图像中您可以看到铅笔和橡皮擦按钮,我想要的是单击铅笔时输入的值应更改为黑色,而其橡皮擦应为白色。
i tried this <button onclick="$('#color-select').val(0,0,0);$('#stroke-select').val(3);">Pencil</button>
我尝试过<button onclick="$('#color-select').val(0,0,0);$('#stroke-select').val(3);">Pencil</button>
<button onclick="$('#color-select').val('255,255,255');$('#stroke-select').val(30);">Eraser</button>
but its not working, its changing the value of brush size, but color is turning black in both cases...need help. 但是它不起作用,它改变了笔刷大小的值,但是在两种情况下颜色都变黑了……需要帮助。
<input type="color" value="#FF8080" id="color-select" />
<input type="number" id="stroke-select" value="10"/>
<button onclick="change_color('#000000' ,'30')">
Pencil</button>
<button onclick="change_color('#ffffff' ,'15')">
Eraser</button>
<script>
function change_color(color ,stroke) {
debugger
$('#color-select').val(color);
$('#stroke-select').val(stroke);
}
</script>
Try Above Code 尝试以上代码
You should use the 6 character hex value for the color. 您应该使用6个字符的十六进制值作为颜色。 The spec for the HTML5 color input requires it. HTML5颜色输入的规范需要它。
Ie: 即:
<button onclick="$('#color-select').val('#ffffff');$('#stroke-select').val(30);">Eraser</button>
<button onclick="$('#color-select').val('#000000');$('#stroke-select').val(3);">Pencil</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.