javascript - giving buttons in an array an own ID -


I need help for a project doing for school, we need to make a booking system for a cinema chairs I created an array to create but how can I give each button my identity?

This is my code:

  function chair () {for (i = 1; i & lt; = 10; i = i + 1) {if (i & Gt; 3 & amp; amp; amp; & amp; amp; & amp; amp; amp; amp; & amp; amp; amp; amp; amp; amp; amp;; & amp;; 8) {document.write ("& gt; Button & gt; Button & lt; / button & gt;"); } Other {document.write ("& lt; Button & gt; Hi & lt; / button & gt;");  
  

Good, you can do this:

  Document.write ("& lt; Button ID = BTn +" + i + "& gt; Button & lt; / button & gt;");  

Side notes:

  1. You & nbsp; & Amp; Mdash; Declare your i variable.

  2. In addition to the reason for doing something else, we start with 0 in the programming 1 :

     For  (i = 0; i & lt; 10; i = i + 1)  

    you don '

  3. i = i + 1 can be written ++ i ("increment i "): (i = 0; i <10; ++ i)

You do not have to do it again, but this (or his cousin i ++ ) will be more common than i = i + 1 .

  • document.write is fine for small square work and so, but just FWIW, you probably do not want to use it in the real world Use instead:

      var btn = document.createElement ("button"); BT.N.ID = "BTN" + Eye; Document.body.appendChild (btn);  
  • HH, as you're learning ...


    Comments

    Popular posts from this blog

    winforms - C# Form - Property Change -

    java - Messages from .properties file do not display UTF-8 characters -

    javascript - amcharts makechart not working -