简体   繁体   English

我有一个范围输入来改变颜色,但它不起作用

[英]I have a Range input in order to change the color, but it doesn't work

THis is my JS code, I wil laslo include my Git, and thank you so much for your time.这是我的 JS 代码,我将 laslo 包括我的 Git,非常感谢您的时间。 https://github.com/bohorquez866/Rest-dish https://github.com/bohorquez866/Rest-dish

var slider = document.getElementById("myRange");
 slider.oniput = () => {
 document.body.style.background = `linear-gradient(90deg, #2b22e43 ${slider.value}%,
     #2b2e43 ${silider.value}%, #ffffff ${silider.value}.1%, #ffffff ${slider.value}100%)`
}

There's a couple of issues with your code as mentioned in the comments:如评论中所述,您的代码存在一些问题:

  • A typo in the slider.oniput handler, it should be slider.oninputslider.oniput处理程序中的一个错字,它应该是slider.oninput
  • Typo(s) in the document.body.style.background string where you used silider instead of slider document.body.style.background字符串中使用了silider而不是slider silider
  • Typo in the HEX value for one of your colors #2b22e43 , it should be #2b22e4在您的一种颜色#2b22e43HEX值中#2b22e43 ,它应该是#2b22e4

Here's a fixed example:这是一个固定的例子:

 var slider = document.getElementById("slider"); slider.oninput = () => { var currValue = slider.value; document.body.style.background = `linear-gradient(90deg, #2b22e4 ${currValue}%, #2b2e43 ${currValue}%, #ffffff ${currValue}.1%, #ffffff ${currValue}%)`; };
 <div> <input type="range" id="slider" name="volume" min="0" max="11" /> <label for="slider">slider</label> </div>

Not sure if this is the effect that you're looking for, but it works.不确定这是否是您正在寻找的效果,但它有效。 Feel free to tweak it as you wish.随意调整它。

Is a syntax error, it's not slider.oniput is slider.oninput, you miss one N, and you write silider.value in the ${}.是语法错误,不是slider.oniput 是slider.oninput,你漏了一个N,你在${} 中写了silider.value。

Code edit below.代码编辑如下。

var slider = document.getElementById("myRange");
 slider.oninput = () => {
     document.body.style.background = `linear-gradient(90deg, #2b22e43 ${slider.value}%,
         #2b2e43 ${slider.value}%, #ffffff ${slider.value}.1%, #ffffff ${slider.value}100%)`
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 js中的颜色变化不起作用 - The change of the color in js doesn't work 按钮不起作用并更改边框颜色 - Button doesn't work and change the border color 为什么我的 function 无法将网格元素更改为输入范围类型的大小? - Why my function to change a grid element to the size of an input of type range doesn't work? ng-change对输入不起作用 - ng-change doesn't work on input jQuery输入更改不起作用 - jQuery input change doesn't work 输入 addEventListener 对更改不起作用 - Input addEventListener doesn't work on change 我试图在浏览器中制作一个画家,但后来它制作了一个“橡皮擦”,但它不起作用,因为它不会改变颜色 - I tried to make a painter in browser, but then it went to making an 'eraser' it didn't work because it doesn't change the color 我的 headerStyle 不起作用。 我试图分配背景颜色,但在我运行它时它没有出现 - My headerStyle doesn't work. I have tried to assign a background color though it doesn't appear when I run it 我想更改页面背景颜色,但是无法在Chrome浏览器中正常运行 - I want to change the page background color, but it doesn't work as I expect in Chrome Ng Bootstrap日期范围选择器[markDisabled]在输入上不起作用 - Ng Bootstrap date range picker [markDisabled] doesn't work on input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM