我正在尝试使用javascript捕获输入值并将其呈现为div元素。我该怎么做才能使其正常工作?
我正在使用querySeclector来获取输入值。当我这样硬编码时:
document.getElementById("result").innerHTML = "Hello World";
它有效,但是当我用存储输入值的变量替换“ Hello World” 时却无效,并且当我执行console.log时,即使没有错误,我也一无所获
HTML
<body>
<div id="container">
<div id="values">
<input id="firstinput" type="text" placeholder="Enter 2 positive figures">
<button id="submit">Submit</button>
</div>
<div id="result"></div>
</div>
<script src="script.js"></script>
</body>
JAVASCRIPT
let submitButton = document.querySelector("#submit"),
showResult = document.getElementById("result").innerHTML,
weightsForLeftAndRightSides = document.querySelector("#firstinput").value;
submitButton.addEventListener("click", weightBalancer);
function weightBalancer() {
showResult = weightsForLeftAndRightSides;
console.log(weightsForLeftAndRightSides);
}
答案 0 :(得分:1)
单击求和按钮时,您需要在weightBalancer中获取输入值
N
答案 1 :(得分:0)
如果我理解您的问题,则可以编写以下代码以将用户输入内容放入div标签:
Error:(40, 86) java: method findOne in interface org.springframework.data.repository.query.QueryByExampleExecutor<T> cannot be applied to given types;
required: org.springframework.data.domain.Example<S>
found: java.lang.String
reason: cannot infer type-variable(s) S
(argument mismatch; java.lang.String cannot be converted to org.springframework.data.domain.Example<S>)
希望这会有所帮助