我决定作为编码练习来制作hyphenuse计算器。它运行良好,但我坚持实施我的Javascript代码到HTML。这里是我的代码:HTML输入和Javascript没有返回值
<!DOCTYPE html>
<html>
<head>
<script>
function getValueA() {
var a = prompt("What is value a?");
}
function getValueB() {
var b = prompt("What is value b?");
}
function hypothenuse(a, b) {
var c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
return c
document.getElementById("result").innerHTML = "Answer is:" + str(c);
}
</script>
</head>
<body>
<p id="result">Answer:</p>
<button type="button" onclick="getValueA()">Input Value a</button>
<button type="button" onclick="getValueB()">Input Value b</button>
<button type="submit" onclick="hypothenuse()">Calculate</button>
</body>
</html>
使用来是返回的字符串是undefined
问题。但是在做了一些关于网站的研究之后,我做了一些调整。最初,变量a
和b
在一个称为getData
的函数中,变量c
等于函数hypothenuse
。我移动了变量c
,因为它在按下Calculate
按钮之前调用了该函数。
所以现在字符串不会改变根本就是。我希望我的问题足够具体。
尝试解析提示 – Alpha2k