我正在尝试制作一个简单的计算器,但它不起作用,有人能告诉我问题出在哪里。 谢谢!
path("upload"){
(post & extractRequestContext) { ctx => {
implicit val materializer = ctx.materializer
implicit val ec = ctx.executionContext
fileUpload("fileUploads") {
case (fileInfo, fileStream) =>
val path = "E:\\"
val sink = FileIO.toPath(Paths.get(path).resolve(fileInfo.fileName))
val wResult = fileStream.runWith(sink)
onSuccess(wResult) { rep => rep.status match {
case Success(_) =>
var ePath = path + File.separator + fileInfo.fileName
readFile(ePath)
_success message_
case Failure(e) => _faillure message_
} }
}
} }
}
答案 0 :(得分:0)
多件事
首先,如果您想获取输入值,您可以访问输入的value
属性
document.getElementById('id').value
第二个,如果您想设置输入value
,请不要使用innerHTML
。它只在您想要更新HTML元素的内容时才有用。
function sumNumbers() {
let num1 = document.getElementById('num1').value;
let num2 = document.getElementById('num2').value;
let sum = Number(num1) + Number(num2);
document.getElementById('result').value = sum;
}
<form>
<div>First Number:</div>
<div> <input type="number" id="num1" /></div>
<div>Second Number:</div>
<div> <input type="number" id="num2" /></div>
<div><input type="button" value="Calculate Sum" onclick="sumNumbers()"/></div>
<div>Result:</div>
<div> <input type="number" id="result" /></div>
</form>
答案 1 :(得分:0)
您没有从输入中提取值, 使用
let num1 = document.getElementById('num1').value
同样适用于settig值,即
document.getElementById('result').value = sum
<form>
<div>First Number:</div>
<div> <input type="number" id="num1" /></div>
<div>Second Number:</div>
<div> <input type="number" id="num2" /></div>
<div><input type="button" value="Calculate Sum" onclick="sumNumbers()" /></div>
<div>Result:</div>
<div> <input type="number" id="result" /></div>
</form>
<script>
function sumNumbers() {
let num1 = document.getElementById('num1').value;
let num2 = document.getElementById('num2').value;
let sum = Number(num1) + Number(num2);
document.getElementById('result').value = sum;
}
</script>
&#13;