Sunday, 15 April 2012

javascript - Add to variable with a button -


I have a script with javascript variables and a button, now every time I press this button, one, I Have tried as you can see in the script below, but there are some issues, the number is not visible and every time the button is clicked, what is wrong?

Javascript:

  var nativeNR = 1; Function addOne () {nativeNR = nativeNR + 1; }  

html:

  & lt; Form id = "form" & gt; & Lt; Input style = "width: 500px;" Type = "add" id = "plusButton" onclick = "addOne ();" / & Gt; & Lt; / Form & gt; Current amount & lt; Span id = "nativeNR" & gt; & Lt; / Span & gt;  

Each time you click on your case, the number will increase. However, you are not displaying it in Span. To do this, you can refer to the element and set it to native NRR.

Your method should be like this

  var nativeNR = 1; Function addOne () {nativeNR = nativeNR + 1; Document.getElementById ("NationNR"). InnerHTML = nativeNR; } & Lt; Form id = "form" & gt; & Lt; Input style = "width: 500px;" Type = "button" id = "plusButton" onclick = "addOne ();" / & Gt; & Lt; / Form & gt; In addition there is no  type = "add"  in it, it should be  type = "button"  

  & lt; Form id = "form" & gt; & Lt; Input style = "width: 500px;" Type = "button" id = "plusButton" value = "add" onclick = "addOne ();" / & Gt; & Lt; / Form & gt; Current amount & lt; Span id = "nativeNR" & gt; & Lt; / Span & gt;  


No comments:

Post a Comment