简体   繁体   English

如何在旁边的跨度中显示“数字类型输入”的值

[英]How to display the value of a “number type input” in a span next to it

I have a number input type element. 我有一个数字输入类型元素。 I want its value to be displayed in the span next to it. 我希望它的值显示在它旁边的范围内。 As I click or scroll on the increase or decrease button inside the input. 当我单击或滚动输入中的增加或减少按钮时。 I want the span's relative value to change. 我要更改跨度的相对值。 Is it possible?? 可能吗??

I have tried to get the value and display in span but did not worked. 我试图获取该值并在跨度中显示,但没有成功。

Javascript Java脚本

 var displayer = document.getElementById('displayer'); var day = document.getElementById('days'); var hrs = document.getElementById('hours'); var s_t = document.getElementById('s_t'); function funcday() { day.style.border = "1.5px solid darkorange"; hrs.style.border = "1.5px solid mediumaquamarine"; s_t.style.border = "1.5px solid darkorange"; s_t.setAttribute("max", 365); var d = s_t.value; document.getElementById('display_d').textContent = d; } function funhrs() { day.style.border = "1.5px solid mediumaquamarine"; hrs.style.border = "1.5px solid darkorange"; s_t.style.border = "1.5px solid darkorange"; s_t.setAttribute("max", 48); var h = s_t.value; document.getElementById('display_h').textContent = h; } 
 #container { display: flex; } .st { width: 60px; margin-right: 10px; } #days, #hours { color: #fff; width: 70px; margin-left: 10px; padding: 6px; cursor: pointer; background-color: mediumaquamarine; border: 1.5px solid mediumaquamarine; text-align: center; font-family: 'Courier'; } .displayer { align-content: center; text-align: center; line-height: 2; margin-left: 20px; margin-right: 20px; font-size: 15px; border: 1px solid white; display: block; float: right; } .displayer span { margin-right: 5px; margin-left: 5px; } 
 <div id="container"> <input type="number" min="1" class="st" id="s_t" autocomplete="off"> <div id="days" onclick="funcday();">Days</div> <div id="hours" onclick="funhrs();">Hours</div> <div id="displayer" class="displayer"> <span id="display_d">00</span><span>Days</span> <span id="display_h">00</span><span>Hours</span> </div> </div> 

您应该在输入元素上添加onchange事件处理程序,并在此处理程序内更改span元素的文本。

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

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