javascript - Add one every time click ADD button -


Need help! Every time I click on the "Add" button, how do I add one?

Every time I click, the number will increase.

When it starts at 0, then 2, and so on.

HTML:

  & lt; Div id = "add_form" & gt; & Lt; Div class = "form-field" & gt; & Lt; Div class = "field" & gt; & Lt; Div class = "no" & gt; 0 & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; A href = "#" id = "add_field" class = "btn btn-default" & gt; Add & lt; / A & gt; & Lt; P & gt; & Lt; Br / & gt; & Lt; / P & gt;   

JQuery:

  $ (document) .ready (function () {var MaxInputs = 8; var InputsWrapper = $ ("# add_form"); Var addButton = $ ("# add_field"); var x = inputswerapper.length; var fieldcount = 1; $ (AddButton). Click (function (e) {if (x & lt; = MaxInputs) {fieldcount ++; $ (InputsWrapper) .append ('
div class = "no"> 1 ';); X ++;} return false;});});

My JQuery is quite bad, you need some help from people.

In addition, there is a JSFDL link

appreciate your help.

You have 1 hardcode, so this can not change it like this From:

  $ (InputsWrapper) .append ('' div class = "field"> 
'+ x +' & Lt; / div & gt; & lt; / div & gt; ');

Check this with the work demo.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -