相对较新的JS。我觉得其他答案似乎对我不起作用......
我尝试输入文字输入值[类型="数字"],使用' for'循环以匹配该值并填充只读输入以显示价格[基于输入的单位数] ...
许多thnaks!
用户输入字段:
<input class="form-control" name="input-users" id="input-users-bus" type="number" value="" onfocus="this.value = '' " onchange="calcUsers()" />
脚本(分钟播放):
var inputUsersBus = document.getElementById('input-users-bus').value;
function calcUsers(){
for(x = 0; x<inputUsers; x++){
if(x == inputUsers){
document.getElementById('sum-price-bus').value = x;
else{
}
}
}
}
输出字段:
<input class="sum-price" name="sum" id="sum-price-bus" type="number" value="" onfocus="this.value = '' " readonly/>
答案 0 :(得分:0)
这是一个解决您问题的实现。只要input-users-bus
更改价格,就会使用getElementById('input-users-bus').value
抓取该值并乘以价格变量。然后将只读字段sum-price-bus
的值设置为结果。
<input class="form-control" name="input-users" id="input-users-bus" type="number" value="" onchange="calcUsers()" />
<input class="sum-price" name="sum" id="sum-price-bus" type="number" value="" readonly/>
<script>
var price = 5.00; // Acquire this price from whatever source you'd like
function calcUsers() {
var users = document.getElementById('input-users-bus').value;
var result = users * price;
document.getElementById('sum-price-bus').value = result;
}
</script>