简体   繁体   English

JS:我如何提交两个单独的值(表单)并将它们显示在 0-24 小时范围内的条形图中(例如,选择了 6 和 12 - 中间小时变为红色

[英]JS: How do I submit two separate values (form) and display them in a bar ranging 0-24 hours (e.g. 6 and 12 are chosen — the in-between hours turn red

So I'm a newbie programmer and I've made a simple form in HTML and CSS, with two inputs (type:"range").所以我是一个新手程序员,我在 HTML 和 CSS 中制作了一个简单的表格,有两个输入(类型:“范围”)。 Using Javascript, I've been struggling to figure out how the two values from these two inputs can be made to change/manipulate a coloured background of a div-bar with values ranging from 0-24.使用 Javascript,我一直在努力弄清楚如何使用这两个输入的两个值来更改/操作值范围为 0-24 的 div-bar 的彩色背景。

Please, any help with suggestions, solutions or links to useful resources will be appreciated.请提供任何有关建议、解决方案或有用资源链接的帮助,我们将不胜感激。 Thank you!谢谢!

So far I've figured out how to display text data by making the submit button add innerHTML to another element, but time, dates and slider values are only displaying in the URL, not the paragraph element or even the console.到目前为止,我已经弄清楚如何通过将提交按钮添加 innerHTML 到另一个元素来显示文本数据,但是时间、日期和 slider 值仅显示在 URL 中,而不是段落元素甚至控制台。 When calling the function I first tried using the id for the parenting form tag, when that failed to log the numbers, I tried using all the IDs for the individual input-tags in the function instead.调用 function 时,我首先尝试使用 id 作为育儿表单标签,但未能记录数字时,我尝试使用 function 中各个输入标签的所有 ID。 Now nothing is displaying and the console message is disappearing so fast that I can't see the error-message, if there is one.现在什么都没有显示,控制台消息消失得如此之快,以至于我看不到错误消息(如果有的话)。 I don't know how to get the numbers to display, let alone connect those values to the div-bar I've made, and after a number of tutorials my brain is too crispy to think.我不知道如何显示数字,更不用说将这些值连接到我制作的 div-bar 了,在学习了一些教程之后,我的大脑太脆弱了,无法思考。

Please, any help with suggestions, solutions or links to useful resources will be appreciated.请提供任何有关建议、解决方案或有用资源链接的帮助,我们将不胜感激。 Thank you!谢谢! [ HTML display + output in URL field ]( https://i.stack.imgur.com/Cd5Op.png ) [ HTML 显示 + URL 字段中的 output ]( https://i.stack.imgur.com/Cd5Op.png )

You can save value of your slider in a variable and further work with it.您可以将 slider 的值保存在一个变量中并进一步使用它。 Hope this example helps:希望这个例子有帮助:

const slider = document.getElementById("myRange");
const sliderOutput = document.getElementById("slider-output"); // empty div to output text

sliderOutput.innerHTML = `<h1>${slider.value}</h1>`

// Update the current slider value (each time you drag the slider handle)
slider.oninput = () => {
  sliderOutput.innerHTML = `<h1>${slider.value}</h1>`
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM