我正在尝试将#output值显示到另一个输入字段中,到目前为止我发现了这个-> http://jsbin.com/oleto5/5/edit?html,js,output
在这里您可以看到何时键入输入字段,显示输入的数据进入< div> which id=output <input id="txt" type="text" />
我希望实现的目标:
1-html中的更改-我希望将#output作为值显示到另一个输入字段中,如下面的<input id="output" type="text" />
2-在脚本的变化-我也想做的计算更改我有名为$final_rate的php变量,我想“输出”由php变量$final_rate
预期代码示例
<body>
<input id="txt" type="text" />
<input id="output" type="text" value=""/>
</body>
<?php $final_rate = "121";?>
<script>
$(function(){
$('#txt').keydown(function(){
setTimeout(function() {
$('#output').text($('#txt').val());
}, 50);
});
});
</script>
在上面的示例中,如果我们在#txt输入字段中输入10000,我们应该会得到一个满分为82.644的简单单词"10000/121 = 82.644“
发布于 2018-06-27 03:07:13
<body>
<input id="txt" type="text" />
<input id="output" type="text" value=""/>
<script>
//put the value in a javascript variable as a Number
var finalRate = <?php echo "121"; ?>;
$(function(){
//bind on the input event, which happens any time the value of the input changes
$('#txt').on('input', function(e){
//console log the rate just for debugging
console.log(finalRate);
//console log the math just for debugging
console.log(parseFloat(e.target.value)/finalRate);
//turn the value in the input into a Number, and perform the math
$('#output').val(parseFloat(e.target.value)/finalRate);
});
});
</script>
</body>
//put the value in a javascript variable as a Number
var finalRate = 121;//'<?php echo "121"; ?>;
$(function() {
//bind on the input event, which happens any time the value of the input changes
$('#txt').on('input', function(e) {
//console log the rate just for debugging
console.log(finalRate);
//console log the math just for debugging
console.log(parseFloat(e.target.value) / finalRate);
//turn the value in the input into a Number, and perform the math
$('#output').val(parseFloat(e.target.value) / finalRate);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="txt" type="text" />
<input id="output" type="text" value="" />
https://stackoverflow.com/questions/51049751
复制相似问题