简体   繁体   English

在文本框中显示变量的值

[英]displaying a variable's value in a text box

var Stars = 0;

setText("Stars", Stars);

onEvent("FF1", "mouseover", function(event) {
  if (Star11 === true) {
    console.log("+1 star");
    var Stars = Stars + 1;
  }
  if (Star12 === true) {
    console.log("+1 star");
    var Stars = Stars + 1;
  }

I am trying to make a text box display the value of variable "Stars" after increasing that variable by 2. The text box is set at 0 and I am unable to get it to change based on the value of variable "Stars" 在将变量增加2之后,我试图使文本框显示变量“ Stars”的值。该文本框设置为0,但无法根据变量“ Stars”的值进行更改

Edit: I have solved the issue 编辑:我已经解决了这个问题

If I understood your question correctly, you can do something like this: 如果我正确理解了您的问题,则可以执行以下操作:

HTML: HTML:

<input id="stars" type="text" value=""/>
<button onclick="addStars()">
Click Me!
</button>

javaScript: JavaScript的:

stars=0;
function addStars() {
    stars = stars + 1;
    document.getElementById("stars").value = "star "+ stars;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM