[英]Add a variable to textfield JavaScript
For my Javascript assignment I have to make a slot machine. 对于我的Javascript作业,我必须制造一台老虎机。
The one part I can't get is adding my totalCredits Variable to my textfield. 我无法获得的一部分是将我的totalCredits变量添加到我的文本字段中。
It just puts the variable beside the credits instead of adding them. 它只是将变量放在积分旁边,而不是添加它们。 (want to add 30 + 2 but I get 302) (想加30 + 2,但我得到302)
I have tried parseFloat and parseInt both give me "ReferenceError: invalid assignment left-hand side" 我尝试过parseFloat和parseInt都给我“ ReferenceError:左侧的赋值无效”
This is the function 这是功能
function checkForWin() {
if (bet1 == true && symbols[rng1].color == symbols[rng2].color && symbols[rng2].color ==
symbols[rng3].color && symbols[rng1].color == symbols[rng3].color) {
document.getElementById("message").innerHTML = "Same Color You Win 2 Credits";
totalCredits = totalCredits + 2;
parseInt(document.getElementById('credits').value) = totalCredits;
console.log(totalCredits);
};
Code : https://jsfiddle.net/Socha/ndLn73bw/ 代码: https : //jsfiddle.net/Socha/ndLn73bw/
Change it as below 如下更改
total = parseInt(totalCredits) + 2;
document.getElementById('credits').value = total;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.