【发布时间】:2018-12-18 20:45:17
【问题描述】:
伙计们,我有一个基本的计算器 js 对象的问题,只能添加数字 input1 + input2 = input3。我不知道如何在输入 3(结果)中显示输入 1 和 2 的结果。从现在开始,我只需使用 show('1') 从输入中获取价值。这是我的代码
JS
function calculator(){
this.result = document.getElementById('3');
this.show = function(id){
var a =document.getElementById(id).value
console.log(a);
}
}
HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<label for="1">
<input type="text" id = '1'>
</label>
<br><br>
<label for="2">
<input type="text" id = '2'>
</label>
<br><br>
<label for="3">
<input type="text" id = 3>
</label>
<button onclick="click()">+</button>
<script src="jss.js"></script>
</body>
</html>
【问题讨论】:
-
你的 click() 函数在哪里?
-
´id`s 不应该是数字。应以字母或下划线开头。
标签: javascript