javascript - 如何使用按钮从 HTML 中的 JavaScript 调用函数?
问题描述
我正在为我的网站构建一个简单的插值和外推元素,用户会看到一个他用数值填写的表格,并且评估是在我的脚本中完成的。这是错误发出的区域,如有必要,我可以分享完整的代码。#JavaScrit 函数:
function Evaluate(){
if (xp > x0 && xp < x1) {
console.log(Interp(x0, y0, x1, y1, xp))
} else if (xp > x0 && xp > x1) {
console.log(Xtrap(x0, y0, x1, y1, xp))
}
#HTML 按钮在表单中:
<button type="button" id="button" onclick="Evaluate()">Evaluate</button>
#来自浏览器控制台查看器的错误(第 27 行是按钮):
Uncaught ReferenceError: Evaluate is not defined
at HTMLButtonElement.onclick (index.html:27)
解决方案
你犯了一个小错误你没有结束你的功能:
function Evalute() {
if (xp > x0 && xp < x1) {
console.log(Interp(x0, y0, x1, y1, xp))
} else if (xp > x0 && xp > x1) {
console.log(Xtrap(x0, y0, x1, y1, xp))
}
}
推荐阅读
- c# - 有没有办法使用 C# 在 Excel 中模仿格式刷?
- javascript - 提取PostgreSQL语法规则
- javascript - 在 OOP 中使用 Angular
- angular - 使用 Angular 在 HTTP 调用中获取表单数据
- python - 如何使用 python3 在 b'\\xe5' 和 b'\xe5' 之间转换?
- amazon-web-services - 获取文件内容作为 Terraform 输出
- javascript - 从 FIrebase 实时数据库中获取数据
- react-native-firebase - 链接帐户时如何从“auth/credential-already-in-use”错误中恢复
- java - 如何通过托管 Bean 在类中设置属性?
- java - 邮递员表单数据发送带有文件的复杂对象