gpt4 book ai didi

javascript - 从范围 slider 更新两个

转载 作者:行者123 更新时间:2023-12-03 10:18:49 26 4
gpt4 key购买 nike

感谢您帮助更新范围 slider 和隐藏字段值中的两个不同值。

目前,这完美地更新了费用输出,并显示了任何 slider 值更改之前的总输出,但当 slider 是用户时,第二个输出显示即。 “undefined300”,其中 300 是 slider 值。它基本上不是添加隐藏字段值。当然我在做一些愚蠢的事情。

<input type="range" min="0" max="100" value="50" id="fee" step="1" oninput="outputUpdate(value)">
<input type="hidden" id="subTotal" value="1000" />

$<output for="fee" id="fee"> </output>

$<output for="fee subTotal" id="total"> </output>

<script>
function outputUpdate(fee, subTotal) {
document.querySelector('#fee').value = fee;
document.querySelector('#subTotal').value = subTotal;
var total = +subTotal + +fee
document.querySelector('#total').value = total;
}
</script>

最佳答案

您正在调用 outputUpdate(value),但您的函数需要两个参数,因为它是 outputUpdate(fee, subTotal){ ... },因此 subTotal 将是“未定义”。还有其他问题。

尝试这个更新的脚本:

<script>
function outputUpdate(fee) {
document.querySelector('#fee').value = fee;
var subTotal = document.querySelector('#subTotal').value;
var total = parseInt(subTotal) + parseInt(fee);
document.querySelector('#total').value = total;
}
</script>

演示:http://jsbin.com/pudequ/1/

关于javascript - 从范围 slider 更新两个 <outputs>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29737226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com