我正在编写一个计算器,尝试获取分配给按钮的“.”。当单击按钮时,我想将按钮的值放入变量中,然后在 div
的内容中显示它。
对于数字,我检索结果,但对于“.”没有发生任何事情。
这是我的 codepen 工作链接: [javascript 计算器][1]
$('button').click(function(){
input = $(this).val();
if (!isNaN(eval(input)) || input === "."){
console.log("input: "+input);
current += input;
log = current;
result += input;
$("#answer").text(current);
$("#history").text(result);
}
});
.val()
调用?我只是说value
是标签button
的有效属性。 - Pierre-Loup Pagniez