build a html code that has a text field and a button when click button call a function and shows the answer in another field
Sure! Here's an example of an HTML code that includes a text field, a button, and another field to display the answer:
<!DOCTYPE html>
<html>
<head>
<title>Answer Display</title>
<script>
function showAnswer() {
var input = document.getElementById("inputField").value;
var answer = input * 2; // Example function: doubling the input
document.getElementById("answerField").value = answer;
}
</script>
</head>
<body>
<h2>Answer Display</h2>
<label for="inputField">Enter a number:</label>
<input type="text" id="inputField" name="inputField"><br><br>
<button onclick="showAnswer()">Show Answer</button><br><br>
<label for="answerField">Answer:</label>
<input type="text" id="answerField" name="answerField" readonly><br><br>
</body>
</html>
In this code, when the user enters a number in the text field and clicks the "Show Answer" button, the showAnswer() function is called. This function retrieves the value entered in the text field, performs a calculation (in this case, doubling the input), and displays the result in the answer field
原文地址: https://www.cveoy.top/t/topic/idx9 著作权归作者所有。请勿转载和采集!