[英]How do I take color Input from users and change color of WIX elements accordingly?
This is the code i've been applying so far which is not working.这是我到目前为止一直在应用的代码,但它不起作用。
$w.onReady(function () {
const bigBox = $w('#box0');
const firstCircle = $w('#box1');
const secondCircle = $w('#box2');
const thirdCircle = $w('#box3');
const fourthCircle = $w('#box4');
const fifthCircle = $w('#box5');
const changeBoxBtn = $w('#changeBox');
const colorInput = $w('#input2') ;
changeBoxBtn.onClick(event => {
bigBox.style.backgroundColor = 'colorInput';
bigBox.style.borderColor = 'colorInput';
});
Refer to the image to see the wix editor view参考图片查看 wix 编辑器视图
We're missing a bit of the big picture in your question, but I'll try my hand at answering anyway.我们在您的问题中遗漏了一些大局,但无论如何我都会尽力回答。
In your onClick
you are setting the background color to a literal string.在您的
onClick
中,您将背景颜色设置为文字字符串。 That's not what you want.那不是你想要的。 You probably want to do something more like this:
你可能想做更多这样的事情:
bigBox.style.backgroundColor = $w('#colorInput').value;
bigBox.style.borderColor = $w('#colorInput').value;
Of course, you are relying on people to input valid color names.当然,您依赖于人们输入有效的颜色名称。 You might want to consider using a dropdown or something similar instead of an open ended text input.
您可能需要考虑使用下拉菜单或类似的东西,而不是开放式文本输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.