【发布时间】:2021-11-29 10:15:27
【问题描述】:
【问题讨论】:
-
请添加相关的 HTML 并尝试解释
"I want when clicked on colours to select them and copy them"~ 哪些颜色?在哪里?它们是否来自上图所建议的input元素?
标签: javascript html select copy-paste
【问题讨论】:
"I want when clicked on colours to select them and copy them" ~ 哪些颜色?在哪里?它们是否来自上图所建议的input 元素?
标签: javascript html select copy-paste
您的问题并不清楚您想做什么。据我了解,您需要通过输入十六进制值来更改颜色,这可以通过 DOM 操作来完成。下面是一个在按钮点击时改变颜色的基本代码。
<html>
<head>
<script>
var colors = ["red", "blue", "green"];
var colorIndex = 0;
function changeColor() {
var col = document.getElementById("body");
if( colorIndex >= colors.length ) {
colorIndex = 0;
}
col.style.backgroundColor = colors[colorIndex];
colorIndex++;
}
</script>
<body id='body'>
<button onclick="changeColor();">Change color</button>
</body>
</html>
同样,您可以只使用输入框中输入的十六进制代码并相应地设置背景/线条颜色。您将需要 js 和 HTML 的帮助,并根据需要使用 if 或 classes。如果有帮助,请点赞。提前谢谢。
【讨论】: