简体   繁体   English

如何从用户那里获取颜色输入并相应地更改 WIX 元素的颜色?

[英]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.

相关问题 使用 type=“color” 从输入中选择颜色时如何更改身体的背景 - How do I change the background of my body when picking a color from my input with the type=“color” 当我输入并提交内容时,如何停止输入表单以更改背景颜色和文本颜色? - How do I stop the input form to change background color and text color when I input and submit something? 如何更改单选输入字段中文本的颜色 - How do i change the color of the text in a radio input field 如何根据 onclick 更改输入字段背景颜色? - How do i change input field background color based on onclick? 如何使用“输入颜色和 onchange”更改 canvas 背景颜色 - How can i change canvas background color with “ input color and onchange ” 从输入中选择颜色后,如何使此按钮更改背景颜色? - How can I make this button change the background color after selecting color from the input? 如何使图像占据页面的一部分,并相应地更改大小? - How Do I Make An Image Take Up A Percent Of A Page, and Change Size Accordingly? 如何从另一个页面更改页面上 div 的颜色 - How do I change the color of div on a page from another page 如何仅更改来自另一个组件的道具的颜色 - How do I change the color of only the props from another component 如何更改由背景颜色确定的文本颜色? - How do I change text-color determined by the background color?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM