gpt4 book ai didi

javascript - 如何使用 JavaScript 更新文本框的背景颜色?

转载 作者:行者123 更新时间:2023-12-02 15:45:56 25 4
gpt4 key购买 nike

我想用javascript制作一个文本框,而不是html(这样可以在console.log中使用它),用setInterval更新背景颜色。怎么办?

这是我到目前为止所得到的,但不起作用。

var x = document.createElement("INPUT");
x.setAttribute("type", "text");
x.setAttribute("value", color);
document.body.appendChild(x);
var color;
setInterval(function(){if (x.setAttribute("value",color)===color{document.body.style.backgroundColor=color};},100);

最佳答案

尝试此解决方案与时间间隔一起使用

var x = document.createElement("INPUT");
x.setAttribute("type", "text");
x.setAttribute("value", color);
document.body.appendChild(x);
var color = '#FFFFFF';
setInterval(function () {
color = x.value; // you need to get value of color code
document.body.style.backgroundColor = color // then it work here
console.log(color);
}, 100);

关于javascript - 如何使用 JavaScript 更新文本框的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32205267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com